SUM PROBLEM

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
问题链接:https://vjudge.net/problem/HDU-1001
问题简述:输入将由一系列整数n组成,每行一个整数。
对于每种情况,输出和(n)在一行中,然后是空行。您可以假设结果在32位带符号整数范围内。
问题分析:简单的数学等差数列求和。
程序说明:输入整数n,从1加到n。
AC通过的C++语言如下:

#include<iostream>
#include <iostream>
using namespace std;
int main()
{    int sum, n, i;
     while (cin >> n) 
     {
                 sum = 0;
              for (i = 0; i <= n; i++) 
     {
                        sum += i;   
     }
                cout << sum << endl << endl;
    }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,451评论 0 10
  • Problem Description Hey, welcome to HDOJ(Hangzhou Dianzi ...
    沙蚕阅读 492评论 0 0
  • 离开简书好长时间了。突然之间不知所措。无从下笔。无法言说。 这半年。和易木创业。奋斗。苦乐参半。两个人在一起相...
    文房姑娘阅读 313评论 0 0
  • 上层的雪很冷吧冷冷的月光照着它下层的雪很沉吧绿绿的草坪盖着它中间的雪 很孤单吧看不见天也看不见地
    摄影师柳丁阅读 123评论 0 1
  • 必须要实话说,我对动物,或者与整个与大自然相关的事情都不太感兴趣。我爬上山顶,但迎面的美景并不会在我脑中轰鸣。小时...
    灰土豆阅读 660评论 1 8