HDU 1008 u Calculate e
2016-07-03 22:52
169 查看
[align=left]Problem Description[/align]
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.
[align=left]Output[/align]
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.
[align=left]Sample Output[/align]
n e
- -----------
0 1
1 2
2 2.5
3 2.666666667
4 2.708333333
[align=left]Source[/align]
Greater New York 2000
简单题
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.
[align=left]Output[/align]
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.
[align=left]Sample Output[/align]
n e
- -----------
0 1
1 2
2 2.5
3 2.666666667
4 2.708333333
[align=left]Source[/align]
Greater New York 2000
简单题
#include<stdio.h> int fact(int n) { int res=1; while(n>=1) { res*=n; n--; } return res; } int main() { printf("n e\n- -----------\n0 1\n1 2\n2 2.5\n3 2.666666667\n4 2.708333333\n"); int n,i; double e; for(n=5;n<=9;n++) { e=0.0; for(i=0;i<=n;i++) { e+=1.0/double(fact(i)); } printf("%d %.9lf\n",n,e); } return 0; }
相关文章推荐
- 购物车总结
- [javaEE] javaweb的mvc设计思想
- Java 8 Lambda表达式探险
- StringUtils 中的 startWith方法和startWithAny方法
- Spring中的依赖原理
- Linux 下 strace 命令用法总结
- HDU1863(最小生成树)
- hessian不能注入dao的问题解决
- 正则判断邮箱练习
- linux grep命令详解
- Android 使用bundle在activity之间交换数据
- 开发中 十六进制的颜色值直接转为ios可用的UIColor
- AJAX局部刷新
- 软件测试Bug和bug生命周期中的各种状态
- 切割合并大文件
- TYVJ 1305 最大字序和
- Java知识点2
- 标准C的标记化结构初始化语法
- C语言文件的编译与执行的四个阶段
- task多任务处理