您的位置:首页 > 其它

sum of all integer numbers

2012-12-09 15:39 239 查看

sum of all integer numbers

时间限制:1000 ms | 内存限制:65535 KB

难度:0

描述 Your task is to find the sum of all integer numbers lying between 1 and
N inclusive.

输入 There are multiple test cases.

The input consists of a single integer N that is not greater than 10000 by it's absolute value.
输出 Write a single integer number that is the sum of all integer numbers lying between 1 and N inclusive.
样例输入
3

样例输出
6

代码

#include<stdio.h>
int main(void)
{
int n;
while(scanf("%d",&n)!=EOF)
{
if(n>0)
printf("%d\n", (n+1)*n/2);
else
printf("%d\n", 1-n*(n-1)/2);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: