Answer to Question #13883 in C++ for najh

Question #13883
c++ program (using while loop)that input a number and output the sum from 1 up to the input value ?
1
Expert's answer
2012-08-30T10:55:20-0400
#include<iostream>
int main()
{
int n;
std::cout <<
"Enter n: ";
std::cin >> n;

int s=0;
for (int i=1; i<=n;
i++)
{
s+=i;
};
std::cout << "Sum of numbers from 1 to "
<< n << " is " << s << std::endl;
return
0;
};

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