hdu 1001 Sum Problem 的解题报告
时间:2011-04-01 来源:琴心&剑胆
链接:http://acm.hdu.edu.cn/showproblem.php?pid=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.
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
View Code
1 5050

1 #include<stdio.h>
2 int main()
3 {
4 int a;
5 int i;
6 while(scanf("%d",&a)!=EOF)
7 {
8 int sum=0;
9 if(a==1) sum=1;
10 else
11 {
12 for( i=1;i<=a;i++)
13 {
14
15 sum=sum+i;
16 }
17 }
18 printf("%d",sum);
19 printf("\n\n");
20
21 }
22 return 0;
23 }
24
相关阅读 更多 +