Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

sum of n natural numbers

//Created by https://ashif.in

#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n; //Take Input
	
  	int sum = n*(n+1)/2;    //Calculate Sum
  	
	cout<<sum;		//Print Sum
  
	return 0;
}
 
PREVIOUS NEXT
Tagged: #sum #natural #numbers
ADD COMMENT
Topic
Name
3+9 =