Answer to Question #17763 in C++ for apoorva

Question #17763
Write a C++ function to sum n natural numbers starting from a given number.
1
Expert's answer
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS