Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

sum of n natural numbers

#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;
}
 
PREVIOUS NEXT
Tagged: #sum #natural #numbers
ADD COMMENT
Topic
Name
3+2 =