C++ Program to Find the Sum of N Natural numbers
source code :
//wap to find the sum of n natural numbers
// n=10 // 1+2+3+4+5+6+7+8+9+10 = 55
#include<iostream>
using namespace std;
int main(){
int n,sum;
cout<<"Enter the value of n : "<<endl;
cin>>n;
sum=n*(n+1)/2; //formula used from class 10
cout<<"The sum of the first "<<n<<" natural number is : "<<sum<<endl;
return 0;
}
output:
ConversionConversion EmoticonEmoticon