In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.
The input will consist of a series of integers n, one integer per line.
For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.
我本来理解的是输入起始数和结尾数,后来不能通过,看了下别人写的才发现需要每输入一个数字就要输出从1到他的和
#include<iostream>
using namespace std;
int main()
{
int i,n,sum=0;
while(cin>>n)
{
for(i=1;i<=n;i++)
sum+=i;
cout<<sum<<endl<<endl;
sum=0;
}
return 0;}