Answers for "sum of n natural no using for loop in c++"

C++
1

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

Code answers related to "sum of n natural no using for loop in c++"

Browse Popular Code Answers by Language