HDU 1012 uCalculate e
来源:互联网 发布:中医之钥 知乎 编辑:程序博客网 时间:2024/04/28 19:08
uCalculate e
Time Limit: 2000/1000 MS (Java/Others) MemoryLimit: 65536/32768 K (Java/Others)
Total Submission(s): 18865 Accepted Submission(s): 8226
Problem Description
A simplemathematical formula for e is
where n is allowed to go to infinity. This can actually yield very accurateapproximations of e using relatively small values of n.
Output
Output theapproximations of e generated by the above formula for the values of n from 0to 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
Recommend
JGShining
解题思路:本题思路非常明确,主要考察的是预处理和精度控制,特别要注意的是输入为8,输出的结果是2.18278770(2.18278768四舍五入而来),%g可以控制浮点型不输出最后面的0;
#include <stdio.h>double a[10]={1,2,2.5};long f[10]={0,1,2,6,24,120,720,5040,40320,362880};int main(int argc, char *argv[]){ int i=0; for(i=3;i<=9;i++) { a[i]=a[i-1]+1.0/f[i]; } printf("n e\n"); printf("- -----------\n"); for(i=0; i<=2;i++) { printf("%d %g\n",i,a[i]); } for(i=3; i<=9;i++) { printf("%d %.9lf\n",i,a[i]); } return 0;}
- HDU 1012 uCalculate e
- HDU 1012 - Calculate e
- HDU 1012 u Calculate e
- HDU 1012 u Calculate e
- HDU 1012 u Calculate e
- HDU--1012--u Calculate e
- hdu 1012 u Calculate e
- HDU 1012 u Calculate e
- hdu 1012 u Calculate e
- u Calculate e hdu 1012
- hdu 1012 u Calculate e
- hdu-1012-u Calculate e
- hdu 1012 u Calculate e
- hdu 1012 u Calculate e
- HDU 1012u Calculate e
- hdu 1012 u Calculate e
- hdu 1012 u Calculate e
- HDU 1012 u Calculate e
- 带游标的存储过程的使用
- 获取选中的第一个radio的值
- VIM分屏功能
- Ajax入门的例子
- 读JSE源码(三)集合之TreeSet
- HDU 1012 uCalculate e
- 安装配置Django开发环境(Eclipse + Pydev)
- ASPxGridView 结合CheckBox实现多选(在后台事件代码控制)
- 转 -- 阿里巴巴公司DBA笔试题
- iPhone/Mac Objective-C内存管理教程和原理剖析(一)基本原理
- Decorator(装饰者)模式
- android用于打开各种文件的intent
- asp.net(C#)中Repeater嵌套绑定Repeater
- 邻接表表示的广度优先搜索