HDU 1001 Sum Problem C/C++
2015-02-07 10:27
453 查看
Problem Description
Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).
In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.
Input
The input will consist of a series of integers n, one integer per line.
Output
For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.
Sample Input
1 100
Sample Output
1 5050
Author
DOOM III
C语言:
C++:
在这里提醒大家,换行符(\n和endl)一定要两个,否则会提示Presentation Error.
代码仅供参考,如果哪里有不足,欢迎各位指教,我一定会及时进行改进和优化。
如果要转载,请注明出处。
2015.2.7 黑骐
Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).
In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.
Input
The input will consist of a series of integers n, one integer per line.
Output
For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.
Sample Input
1 100
Sample Output
1 5050
Author
DOOM III
C语言:
#include <stdio.h> main() { int sum, n, i; while (scanf("%d", &n) != EOF) { sum = 0; for (i = 0; i <= n; i++) { sum += i; } printf("%d\n\n", sum); } }
C++:
#include <iostream> using namespace std; main() { int sum, n, i; while (cin >> n) { sum = 0; for (i = 0; i <= n; i++) { sum += i; } cout << sum << endl << endl; } }
在这里提醒大家,换行符(\n和endl)一定要两个,否则会提示Presentation Error.
代码仅供参考,如果哪里有不足,欢迎各位指教,我一定会及时进行改进和优化。
如果要转载,请注明出处。
2015.2.7 黑骐
相关文章推荐
- hdu 1001 Sum Problem 的解题报告
- hdu 1001 Sum Problem 解题报告 数据范围
- hdu1001 Sum Problem
- HDU 1001 Sum Problem JAVA
- HDU 1001 Sum Problem
- HDU 1001 Sum Problem(水题)
- hdu 1001 sum problem
- HDU 1001【Sum Problem】
- HDU 1001 Sum Problem(水~)
- HODJ 1001 Sum Problem C++解法
- hdu1001 Sum Problem 差点被这个题玩死了
- 【HDU】-1001-Sum Problem(水,变态)
- HDU 1001 Sum Problem 水题
- HDU 1001 Sum Problem python实现
- HDU-1001(Sum Problem)
- hdu 1001 Sum Problem(Java)
- hdu1001 Sum Problem (等差数列求和)
- HDU 1001 Sum Problem
- HODJ 1001 Sum Problem C++解法
- JAVA hdu 1000(A + B Problem)&&hdu 1001(Sum Problem)