文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>hdu 1001 Sum Problem 的解题报告

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.
 
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
 
View Code
 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
排行榜 更多 +
疯狂兔子人乐园

疯狂兔子人乐园

休闲益智 下载
空中飞机飞行

空中飞机飞行

休闲益智 下载
小姐姐历险记2

小姐姐历险记2

休闲益智 下载