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("%dnn",sum);
12 }
13 }
复制代码
作者 任琦磊
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/c-cdevelopment/603889.html