Description
Your task is to find the sum of all integer numberslying between 1 and N inclusive.
Input
The input consists of a single integer N that isnot greater than 10000 by it's absolute value.
Output
Write a single integer number that is the sum of allinteger numbers lying between 1 and N inclusive.
Sample Input
-3
output
-5
代码:
#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
if(n>0)
cout<<(n*(n+1))/2;
else
cout<<((2-n)*(n+1))/2<<endl;
return 0;
}