1+2+3+......+n
2015-07-20 11:33
260 查看
[align=left]Problem Description[/align]
Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).
In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.
[align=left]Input[/align]
The input will consist of a series of integers n, one integer per line.
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
[align=left]Sample Output[/align]
Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).
In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.
[align=left]Input[/align]
The input will consist of a series of integers n, one integer per line.
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
1 100
[align=left]Sample Output[/align]
1 5050
#include<stdio.h> int main() { int i,n,sum; while(scanf("%d",&n)!=EOF) { sum=0; for(i=1;i<=n;i++) sum+=i; printf("%d\n",sum); printf("\n"); } return 0; }
相关文章推荐
- .Net操作音频
- Algorithms—150.Evaluate Reverse Polish Notation
- 2013下半年软件评测师真题考试分析-4
- java 反射 reflect
- 为eclipse离线安装hibernate tools插件
- Github上README.md介绍 语法
- 我佩服-WPF(2)
- Android系统APN配置具体解释
- php将数组写入配置文件
- OpenCV学习:将图像转为二值图像(函数cvtColor和函数threshold)
- 多客户端上传服务器文档使用scp命令不需要输入密码
- 要成为linux网站运维工程师必须要掌握的技能
- visio 2010如何激活
- 希尔排序(shellsort)
- Hibernate处理一个实体映射多张相同结构的数据表--动态映射
- frostwire项目源码分析
- Linux下抓取log的方法
- UVa 11572
- mysql小技巧 用rand()写随机查询
- linux防火墙iptables原理及使用