sum of n natural no using formula in c++ n(n+1)/2 code example
Example: sum of n natural no using for loop in c++
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
int sum=0;
cin>>n;
for(int i=1;i<=n;i++)
{
sum+=i;
}
cout<<sum<<" ";
cout<<endl;
return 0;
}