设为首页 加入收藏

TOP

HDUacm 1001 Sum Problem
2014-11-24 00:43:40 来源: 作者: 【 】 浏览:73
Tags: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
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 }
复制代码

作者 任琦磊

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇用C做的电子时钟程序 下一篇HDUacm 1002 A + B Problem II

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: