题目要求:
Problem Description
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.
//注意,此处要求每个输出占一行,之后还需空一行,即输出需要两个“\n”
Sample Input
1
100
Sample Output
1
5050
代码实现:
#include<stdio.h>
int main(int argc, char **argv)
{
int i,n,s;
i=0,n=0,s=0;
while(scanf("%d",&n)!=EOF)
{
for(i=0; i<=n; i++)
{
s+=i;
}
// 此处两个“\n”为题目要求的,否则会出现Presentation Error
printf("%d\n\n",s);
s=0;
}
return 0;
}