1049 - Sum
Description
Your task is to find the sum of all integer numbers lying between 1 andNinclusive.
Input specification
The input consists of a single integer
Nthat is not greater than 10^4 by it's absolute value.
Output specification
Write to the output a single integer number that is the sum of all integer numbers lying between 1 and
Ninclusive.
Sample input
3
Sample output
6
void sumMinusAndPositives()
{
int n = 0;
cin>>n;
int t = n < 0? -n : n;
int ans = (n < 0) ? (1 - ((1+t)*t) / 2) : (((1+t)*t) / 2);
if (0 == n) ans = 1;
cout<<ans<<endl;
}