HDOJ1001
题目
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. 【输出包括SUM和空行!】
Sample Input1
100
Sample Output1
5050
代码
//C代码
#include<stdio.h>
int main()
{
int n, i, sum;
sum = 0;
while(~scanf("%d", &n))
{
sum = 0;
for(i=1;i<=n;i++)
{
sum+=i;
}
printf("%d\n\n", sum); //注意是两个\n
}
}
Conclusion
这一题没有什么难度,就是求从1到n的和。但简单的题目同样要注意要求,否则在OJ上无法通过。