杭电1001
来源:互联网 发布:软件空免费下载 编辑:程序博客网 时间:2024/05/22 14:13
Sum Problem
Time Limit: 1000/500 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 191420 Accepted Submission(s): 45769
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.
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
1100
Sample Output
15050今天学习了递归。用递归来写了一下。#include <iostream>using namespace std;int n;int ans(int x){if(x == 1)return 1;elsereturn x+ans(x-1);}int main(){while(cin >> n){cout << ans(n) << endl; cout << endl;}return 0;}
- 杭电acm 1001
- 杭电 1001
- 杭电1001
- 杭电ACM 1001
- 杭电1001
- 杭电 oj 1001
- 杭电OJ 1001
- 杭电1001
- 杭电1001
- 杭电1000,1001
- 杭电ACM 1001
- 杭电1001题
- 杭电oj~~1001
- 杭电ACM 1001
- 杭电ACM 1001
- 杭电ACM----1001
- 杭电 1001
- 杭电1001
- 移动桌面图标位置
- 项目管理的“三边六拍
- VC++、MFC中最好的开源项目
- WEB 加密解密小系统
- CSMA/CA协议分析
- 杭电1001
- maven 管理项目实践指南
- poj 3299 Humidex lightblueme
- JavaMail邮件发送-能发送附件和带背景音乐的邮件的小系统
- 搭建LNMP(linux+nginx+mysql+php)服务器环境配置实例教程
- InputStream和OutputStream
- Seam 无缝集成 JSF
- PreparedStatement和Statement的区别
- 如何保障移动设备的安全