Your task is to find the sum of all integer numbers lying between 1 and N inclusive.
输入
An integer number that is not greater than 10000
输出
The sum according to the rule above.
样例输入
-3
样例输出
-5
代码:
#include<stdio.h>
int main()
{
int n,i,sum;
sum=0;
scanf("%d",&n);
if(n<=0)
{
for(i=n;i<=1;i++)
sum+=i;
}
else
{
for(i=1;i<=n;i++)
sum+=i;
}
printf("%d\n",sum);
return 0;
}