4 C++ Program To Calculate Sum of Natural Numbers
4 C++ Program To Calculate Sum of Natural Numbers
A DV E RT I S E M E N T S
To understand this example, you should have the knowledge of the following C++
programming topics:
This program takes a positive integer from user( suppose user entered n ) then,
this program displays the value of 1+2+3+....+n.
#include <iostream>
using namespace std;
int main() {
int n, sum = 0;
Output
A DV E RT I S E M E N T S
This program can also be done using recursion. Check out this article for
calculating sum of natural numbers using recursion.
A DV E RT I S E M E N T S
Related Examples
Tutorials Examples
Join our newsle er for the latest Python 3 Tutorial Python Examples
updates.
JavaScript Tutorial JavaScript Examples
Swi Tutorial
C# Tutorial
DSA Tutorial
Company Apps
Contact
Blog
Youtube