And n items seeking HDU 1001

HDU 1001 Sum Problem 2019.3.21.2

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

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

Summarize
this question there are three areas that need attention.
First, sum = 0 position while loop is placed inside or on the outside?
Second, there is a blank line in the output format, how to achieve output of blank lines it?
Third, the location of the white line is the result on the sum, or on the results of it before?

Released seven original articles · won praise 4 · Views 3096

Guess you like

Origin blog.csdn.net/qq_39634669/article/details/88723704
Recommended