Sum Problem-hdu-1001
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
#include<stdio.h>
#include<stdlib.h>
int main()
{
int n,sum;
while(scanf("%d",&n)!=EOF)//多次输入
{
sum=0;//放入循环体内,保证每次sum都被清0
while(n)//当n!=0时,执行循环
{
sum+=n;//累加
n=n-1;
}
printf("%d\n\n",sum);//输出结果
}
return 0;
}
Sum Problem-hdu-1001的更多相关文章
- HDu 1001 Sum Problem 分类: ACM 2015-06-19 23:38 12人阅读 评论(0) 收藏
Sum Problem Time Limit: 1000/500 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- HDU 2058 The sum problem(枚举)
The sum problem Problem Description Given a sequence 1,2,3,......N, your job is to calculate all the ...
- HDU 2058:The sum problem(数学)
The sum problem Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- D - Ugly Problem HDU - 5920
D - Ugly Problem HDU - 5920 Everyone hates ugly problems. You are given a positive integer. You must ...
- Prime Ring Problem HDU - 1016 (dfs)
Prime Ring Problem HDU - 1016 A ring is compose of n circles as shown in diagram. Put natural number ...
- summary of k Sum problem and solutions in leetcode
I found summary of k Sum problem and solutions in leetcode on the Internet. http://www.sigmainfy.com ...
- Subset sum problem
https://en.wikipedia.org/wiki/Subset_sum_problem In computer science, the subset sum problem is an i ...
- HD2058The sum problem
The sum problem Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- Maxmum subsequence sum problem
We have a lot of ways to solve the maximum subsequence sum problem, but different ways take differen ...
- NYOJ--927--dfs--The partial sum problem
/* Name: NYOJ--927--The partial sum problem Author: shen_渊 Date: 15/04/17 19:41 Description: DFS,和 N ...
随机推荐
- web 前端 shopnc项目 首页分类一开始做前端,我是拒绝的
看图别说话 经过几小时的折腾 主要还是靠耐心
- Python模块的介绍
Python模块的学习: 1.os模块: 下面只对os模块中几个比较常用的方法做一些简单的示例: os.system():这个方法在shell中体现的比较多,在dos命令行中也可以执行,下面就以在do ...
- OS-MAC: An Efficient MAC Protocol for Spectrum-Agile Wireless Networks
IEEE TRANSACTIONS ON MOBILE COMPUTING, VOL. 7, NO. 8, AUGUST 2008 正如之前所说的,这是一个out-of-band local cove ...
- USB封包格式
1.起始(SOP)封包 根集线器会在每1 ms时,送出SOF封包.这介于2个SOF封包之间的时间,即称为帧(frame).SOF封包虽是属于令牌封包的一种,但却具有独自的PID形态名称SOF.通常目标 ...
- logstash 解析mysql slow log
# User@Host: zjzc_app[zjzc_app] @ [10.252.148.16xx] Id: 6043127 # Query_time: 2.581184 Lock_time: 0. ...
- JavaScript加密解密7种方法总结分析
原文地址:http://wenku.baidu.com/view/9048edee9e31433239689357.html 本文一共介绍了七种javascript加密方法: 在做网页时(其实是网页木 ...
- UESTC_握手 CDOJ 913
握手 Time Limit: 2000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit Status ...
- Summary Ranges 解答
Question Given a sorted integer array without duplicates, return the summary of its ranges. For exam ...
- python使用get在百度搜索并保存第一页搜索结果
python使用get在百度搜索并保存第一页搜索结果 作者:vpoet mail:vpoet_sir@163.com 注:随意copy,不用在意我的感受 #coding:utf-8 import ur ...
- Grails重定向以及Render、Session的使用
近期发现网上grails因为用的人不算非常多,相关的资料也不是那么easy找到,随着学习的深入打算把我的学习心得定期分享出来.也给学习grails的同胞一个偷懒的机会,我的原则是以最简洁的方式学会Gr ...