64 693
Assignments Done
99,3%
Successfully Done
In September 2018

Answer to Question #17763 in C++ for apoorva

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

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions