Sum Problem
2015-10-29 11:34
369 查看
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
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
#include<stdio.h> int main() { int i,n,sum=0; while(scanf("%d",&n)!=EOF) { for(i=1;i<=n;++i) sum=sum+i; printf("%d\n\n",sum); sum=0; } return 0; }
相关文章推荐
- 2015 Multi-University Training Contest 6 Solutions
- HDOJ 1002 A + B Problem II (Big Numbers Addition)
- HDOJ 1009
- HDOJ 1001 递归方法
- HDOJ 1002 C语言版
- HDOJ 1003题解
- Big Number
- hdoj 2036 改革春风吹满地
- hdu 3076 ssworld VS DDD 概率dp
- hdu5007 ACM-ICPC 西安赛区网赛A题 水题
- hdu5011 西安邀请赛E题 Game 博弈论
- hdu5012 ACM-ICPC 西安赛区E题 Dice
- 最小生成树——HDOJ 1233 还是畅通工程 解题报告
- 并查集——HDOJ 1213How Many Tables解题报告
- 最小生成树——HDOJ 2988 Dark roads解题报告
- hdoj1001解题报告
- HDOJ 1010 Tempter of the Bone DFS+剪枝
- HDOJ 1312 Red and Black 基础DFS
- HDOJ 1253 胜利大逃亡 BFS
- HDOJ 1242 Rescue 优先队列+bfs