今天因为自己不知道在做什么,然后拖到晚上才做的
1001题目
Problem Description
Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).
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
Sample Output
Author
DOOM III
刚开始,英文不好,然后刚开始以为是输入两个数,先输入第一个起始数字,结果提交发现错误啊,我也是醉了,后来搞百度了一下,发现原来这里不是输入两个数,一个数就好了,刚开始应该是没有难度的题,坚持才是胜利
我的代码是这样的
#include
int main()
{
int a,b,sum = 0,i=1;
while(scanf("%d",&b)!=EOF)
{
for(i =1;i<=b;i++)
sum+=i;
printf("%d\n\n",sum);
sum=0;
}
return 0;
}
继续坚持,坚持才是胜利。加油