Answer to Question #13883 in C++ for najh
c++ program (using while loop)that input a number and output the sum from 1 up to the input value ?
1
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!
Learn more about our help with Assignments:
C++
Comments
Leave a comment