HDOJ 1001

View Code
 1 /*
 2 Sum Problem
 3 
 4 Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
 5 Total Submission(s): 171363    Accepted Submission(s): 40796
 6 
 7 
 8 Problem Description
 9 Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).
10 
11 In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.
12  
13 
14 Input
15 The input will consist of a series of integers n, one integer per line.
16  
17 
18 Output
19 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.
20  
21 
22 Sample Input
23 1
24 100
25  
26 
27 Sample Output
28 1
29 
30 5050
31  
32 
33 Author
34 DOOM III
35  
36 
37 */
38 
39 #include <iostream>
40 using namespace std;
41 
42 int main()
43 {
44     int sum , n;
45     int i;
46     while(cin>>n)
47     {
48         sum = 0;
49         for (i=0; i<=n; i++)
50             sum += i;
51         cout<<sum<<endl<<endl;
52     }
53     return 0;
54 }
posted @ 2012-10-13 21:42  旅行的蜗牛  阅读(119)  评论(0编辑  收藏  举报