C++ Program to Find the sum of First N natural Number
In this article, we will see C++ Program to Find the Sum of First N Natural Numbers. A Natural number is the same as a Counting number. They are used to Count the number of real physical objects. Natural numbers start from 1 and go on infinite.
The positive numbers 1,2,3 ... are known as natural numbers.
The formula for the Sum of First n natural numbers is n(n+1)/2.
If you want to add the first 5 Natural numbers then we find the Sum of 1+2+3+4+5 =15.
Declare and initialize variable, i,num, s=0.
Enter the value of num i.e. number up to which sum is to be calculated.
Use Loop to add numbers. Any of while, do-while or for loop can be used.
Print the sum.
using namespace std;
cout << "Enter a number : ";
cin >> n;
cout << sum;
Sum is 15