Answer to Question #17763 in C++ for apoorva
Write a C++ function to sum n natural numbers starting from a given number.
1
2012-11-05T09:59:12-0500
#include <iostream>
using namespace std;
int sum(int N)
{
intS = 0;
for(inti = 0; i <= N; i++)
S+= i;
returnS;
}
void main()
{
intn;
cout<< "Enter the number: ";
cin>> n;
cout<< sum(n) << endl;
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
C++
Comments
Leave a comment