Your task is to find the sum of all integer numbers lying between 1 and Ninclusive.
Input
The input consists of a single integer N that is not greater than 10000 by it's absolute value.
Output
Write a single integer number that is the sum of all integer numbers lying between 1 and N inclusive.
Example
input | output |
---|---|
| |
#include <stdio.h>
int main(){
int n, sum;
while(~scanf("%d", &n)){
sum = 0;
if(n < 1)
sum = n*(1-n)/2 + 1;
else sum = n*(n+1)/2;
printf("%d\n", sum);
}
return 0;
}