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;
}
}