1001
2015-02-12 19:20
155 查看
Sum Problem
Problem Description
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.//只有无符号的需要显式定义,如果没有unsigned
标识,就是有符号的。
Sample Input
1
100
Sample Output
1
5050
Author
DOOM III
Problem Description
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.//只有无符号的需要显式定义,如果没有unsigned
标识,就是有符号的。
Sample Input
1
100
Sample Output
1
5050
Author
DOOM III
#include <iostream> using namespace std; int main() { int a,n; while(cin>>a) { int i=0; while(a) { i=i+a;//i为从1到a的和 a--; } cout<<i<<endl; cout<<endl; } return 0; }
相关文章推荐
- 1001.A+B Format
- 九度 题目1001:A+B for Matrices
- BestCoder Round #29 1001 GTY's math problem
- PAT A1001 A+B Fomat
- 题目1001: A+B for Matrices
- URAL1001解题报告
- 1001. A+B Format
- 杭电ACM 1001:Sum Problem
- PAT (Basic Level) Practise 1001
- 贪心 BestCoder Round #39 1001 Delete
- BestCoder Round #40 1001——精度——Tom and paper
- 2015年百度之星程序设计大赛 - 资格赛 (1001 大搬家)
- A+B for Matrices_1001
- YT02-简单数学课堂题-1001 Rightmost Digit-(5.31日-烟台大学ACM预备队解题报告)
- 百度之星 2015 复赛 1001 (数长方形)
- bzoj 1001 分类: bzoj 2015-06-27 16:05 24人阅读 评论(0) 收藏
- hdu4883/BestCoder#2_1001
- pat 1001. A+B Format (20)
- 多校1 OO’s Sequence 1001
- BZOJ 1001 狼抓兔子