传送门:

http://acm.hdu.edu.cn/showproblem.php?pid=1012

u Calculate e

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 52607    Accepted Submission(s): 24106

Problem Description
A simple mathematical formula for e is

where n is allowed to go to infinity. This can actually yield very accurate approximations of e using relatively small values of n.

Output
Output the approximations of e generated by the above formula for the values of n from 0 to 9. The beginning of your output should appear similar to that shown below.
Sample Output
n e
- -----------
0 1
1 2
2 2.5
3 2.666666667
4 2.708333333

Source
Greater New York 2000
分析:
没有什么好说的
水题
code:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int f(int x)
{if(x==0)return 1;if(x==1)return 1;LL sum=1;for(int i=1;i<=x;i++){sum*=i;}return sum;
}
int main()
{printf("n e\n");printf("- -----------\n");printf("0 1\n1 2\n2 2.5\n");for(int i=3;i<=9;i++){double result=0;for(int j=0;j<=i;j++){result+=(1.0/(f(j)*1.0));}printf("%d %0.9lf\n",i,result);}return 0;
}

转载于:https://www.cnblogs.com/yinbiao/p/9313265.html

HDU 1012 u Calculate e(简单阶乘计算)相关推荐

  1. PTA 基础编程题目集 6-8 简单阶乘计算 C语言

    PTA 基础编程题目集 6-8 简单阶乘计算 C语言 本题要求实现一个计算非负整数阶乘的简单函数. 函数接口定义: int Factorial( const int N ); 其中N是用户传入的参数, ...

  2. 简单阶乘计算 (本题要求实现一个计算非负整数阶乘的简单函数)

    6.简单阶乘计算 本题要求实现一个计算非负整数阶乘的简单函数. 实现代码: int Factorial(const int N ) {int i,n=1;if(N>=0){for(i=0;i&l ...

  3. 4-8 简单阶乘计算 (10分)

    本题要求实现一个计算非负整数阶乘的简单函数. 函数接口定义: int Factorial( const int N ); 其中N是用户传入的参数,其值不超过12.如果N是非负整数,则该函数必须返回N的 ...

  4. PTA之简单阶乘计算

    本题要求实现一个计算非负整数阶乘的简单函数. 时间限制: 400ms 内存限制: 64MB 代码长度限制: 16KB 函数接口定义: int Factorial( const int N ); 其中N ...

  5. 6-8 简单阶乘计算(10 分) 本题要求实现一个计算非负整数阶乘的简单函数。

    int Factorial( const int N ); 其中N是用户传入的参数,其值不超过12.如果N是非负整数,则该函数必须返回N的阶乘,否则返回0. int Factorial( const ...

  6. PTA基础编程题目集-6-8 简单阶乘计算

    int Factorial( const int N ){int fact=1;if(N<0)return 0;for(int i=1;i<=N;i++){fact*=i;}return ...

  7. 基础编程题目集 6-8 简单阶乘计算 (10 分)

    问题描述: 解题思路: 由于数据很小,所以直接递归即可 解题代码: int Factorial( const int N ){if(N < 0) return 0;if(N == 0 || N ...

  8. python【蓝桥杯vip练习题库】ALGO-231多阶乘计算

    试题 算法训练 多阶乘计算 资源限制 时间限制:1.0s 内存限制:256.0MB 问题描述 我们知道,阶乘n!表示n*(n-1)(n-2)-21, 类似的,可以定义多阶乘计算,例如:5!!=531, ...

  9. python 递归函数_Python尚学堂高淇|P82P86面向对象和面向过程的区别LEGB规则nonlocal_global递归函数阶乘计算案例...

    P82-递归函数-阶乘计算案例 #使用递归函数计算阶乘def factorial(n):if n==1:return 1else:return n*factorial(n-1)result=facto ...

最新文章

  1. 深入JDK源码,这里总有你不知道的知识点!
  2. 09Abstract Factory(抽象工厂)模式
  3. iPhone拍人像,人头直接不见了,什么情况?
  4. python读取excel某一行-Python 读取csv的某行
  5. mysql判断存在返回布尔_MySqlClient访问tinyint字段返回布尔值篇
  6. springboot细节挖掘(监听器)
  7. Shiro报异常org.apache.shiro.authz.AuthorizationException: Not authorized to invoke method:
  8. 【译】5 个你需要知道的 JavaScript 小技巧
  9. 速修复!这个严重的 Apache Struts RCE 漏洞补丁不完整
  10. 分享一个圆角自定义的漂亮AlertDialog
  11. LINUX CGROUP 概述
  12. c# 数组不能直接=,需要clone
  13. 电力-104规约实际测试1
  14. python接受前端传递的参数
  15. CLodop start
  16. 浙江省二级计算机vfp,浙江省高校计算机等级考试大纲(二级——VisualFoxPro语言程序设计大纲)...
  17. oracle的odac dll,.NET2.0中施用最少的ODAC动态库文件连接Oracle数据库
  18. 注意JDBC数据库连接中资源关闭的顺序
  19. 儿童摄影HTML实现
  20. TTL expired in transit

热门文章

  1. .Net开发人员通过WCF使用Node.js
  2. centos overlay 占用很大_盘锦技术好的升降货梯占用空间小
  3. scp 上传文件到服务器
  4. linux中hadoop环境变量配置文件,Ubuntu中关于hadoop环境变量的设置方法
  5. mysql镜像备份和同步备份_mysql 主从同步及备份
  6. 五人合伙最佳股份分配_【干货要点】再谈“类直营”——百果园的店长合伙人...
  7. 计算机绘图图库的创建,工程制图与计算机绘图.doc
  8. 丁卓雅计算机学院,幼儿园音乐教育教学研讨会暨许卓雅教授音乐专题讲座
  9. 局域网制作ftp服务器,如何架设内网ftp服务器 搭建ftp yum源
  10. 为什么C语言输出结果总是1,c语言编程问题这个题我哪里错了输出结果总是0