hdoj 第二题

Sum Problem

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.
(输入将由一系列整数n组成,每行一个整数)

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.
(对于每种情况,在一行中输出SUM(n),后跟一个空行。您可以假设结果在32位有符号整数的范围内)

Sample Input

1
100

Sample Output

1

5050

Source Code

#include<stdio.h>
int main()
{
 int i,n,sum;
 while(scanf("%d",&n)!=EOF)
 {
  sum=0;
  for(i=1;i<=n;i++)
  {
   sum+=i;
  }
  printf("%d\n\n",sum);
 }
 return 0;
}
发布了2 篇原创文章 · 获赞 0 · 访问量 6
展开阅读全文
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 游动-白 设计师: 上身试试

分享到微信朋友圈

×

扫一扫,手机浏览