您的位置:首页 > 其它

HDU 1001 Sum Problem(水~)

2015-09-04 08:33 387 查看
Description

给出一整数n,输出sum(n)=1+2+…+n的值

Input

多组输入,每组用例占一行为一整数n

Output

输出sum(n)的值,每组输出后跟一空行

Sample Input

1

100

Sample Output

1

5050

Solution

n过大,可以用double代公式过

Code

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