HDUacm 1001 Sum Problem
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
1 100
sample output
1 5050
codes:
1 #include <stdio.h>
2 main()
3 {
4 int a,i,sum;
5
6 while(scanf("%d",&a)!=eof)
7 {
8 sum=0;
9 for(i=1;i<=a;i++)
10 sum=sum+i;
11 printf("%d\n\n",sum);
12 }
13 }
复制代码
作者 任琦磊
上一篇: js构造超简洁顺序链表的方法(代码实现)
下一篇: 哥们间的搞笑传情短信
推荐阅读
-
HDUacm 1000 A + B Problem
-
ACM1001:Sum Problem
-
LeetCode Problem -- 404. Sum of Left Leaves -
[LeetCode&Python] Problem 404. Sum of Left Leaves
-
HDUacm 1001 Sum Problem
-
HDUacm 1002 A + B Problem II
-
HDUacm 1000 A + B Problem
-
The Sum Problem HDU 2058
-
hdu2058The sum problem解题报告---等差数列的和(数论)
-
Summary_(hdu 2058)_(The Sum Problem)