In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.
Input
The input will consist of a series of integers n, one integer per line.
Output
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.
Sample Input
1
100
Sample Output
1
5050作者: X嘉葰 时间: 2009-11-4 00:55
这么简单?我是不是没读懂题目啊?作者: 致命のdu 时间: 2009-11-4 00:55
就是要求输入几个数据,输出他们的相加和,第一行表示输入几行数据作者: 淡淡的烟草味 时间: 2009-11-4 00:55
那数据大小呢 ?作者: 边走¤边爱 时间: 2009-11-4 00:55
#include<iostream.h>
void main()
{
int n,temp,sum;
cout<<"请输入一个整数n:";
cin>>n>>endl;
for(temp=n;temp<=n;temp++)
{
sum+=temp;
}
cout<<sum<<endl;
}作者: 丑剑客 时间: 2009-11-4 00:55
这个题目int 可能不够的作者: ※随风飘荡※ 时间: 2009-11-4 00:55
int sum()
{
cout<<"Please input a series of integers(end with 0).\n";
int i,sum=0;
while(cin>>i,i!=0)
sum+=i;
return sum;
}