杭电oj 1001

房东的猫 提交于 2019-11-30 05:49:00

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

Author
DOOM III

Recommend
We have carefully selected several similar problems for you: 1002 1090 1003 1091 1004

#include<iostream>
using namespace std;
int main()
{
    int a,n,sum;
    while(cin>>a)
    {
        sum=0;
        for(n=1;n<=a;n++)
        {
            sum=sum+n;
        }
        cout<<sum<<endl<<endl;
    }
    return 0;
}

这里有个很无聊的小陷阱,“ followed by a blank line”(然后再输出空白行)。

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!