Answers for "formula for sum of n numbers"

1

sum of all n integers

Sum of n integers 1 + 2 + 3 + ... + n = n * (n + 1) / 2
Posted by: Guest on April-06-2021
1

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;
}
Posted by: Guest on June-06-2021
1

formula for sum of n numbers

Sum of the First n Natural Numbers. We prove the formula 1+ 2+ ... + n = n(n+1) / 2, for n a natural number
Posted by: Guest on December-20-2020

Code answers related to "formula for sum of n numbers"

Browse Popular Code Answers by Language