欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

HDUacm 1001 Sum Problem

程序员文章站 2022-06-07 20:41:31
problem description     hey, welcome to hdoj(hangzhou dianzi university on...

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 <stdio.h>
 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 }
复制代码

 作者 任琦磊