HDOJ 1012
2016-03-19 11:26
295 查看
[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]
[/code]
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[code]#include <iostream> #include <cstring> using namespace std; int a[]={1,1,2,6,24,120,720,5040,40320,362880}; double func(int i) { double r; r=1.0/a[i]; return r; } int main() { double sum=0; cout<<"n e"<<endl; cout<<"- -----------"<<endl; for(int i=0;i<=9;i++) { sum+=func(i); //cout<<i<<" "<<sum<<endl; cout<<i<<" "; if(i>=3) printf("%.9f",sum); else cout<<sum; // if(i!=9) cout<<endl; } return 0; }
[/code]
相关文章推荐
- NYOJ325
- BZOJ-1876 SuperGCD Python(欧几里德算法)
- getParameter() getInputStream()和getReader() 区别
- hash冲突的解决方法以及hashMap的底层实现
- NOIP2014P4 子矩阵 题解
- latex: 改变图的caption Figure 1:为 Fig. 1.
- ACM1006电梯
- AD本地域组和全局组的区别
- memset的基本用法
- YTU 2209: 建立链表(线性表)
- Codeforces 637D Running with Obstacles 【贪心】
- 常用正则表达式整理集锦
- 剑指offer面试题之数字在排序数组中的出现次数
- 网易2016研发工程师编程题 搜索
- 简易版子线程更新UI
- Easyui 更改datagrid 字体大小
- Codeforces 637C Promocodes with Mistakes 【构造】
- Codeforces 637B Chat Order 【模拟】
- 剑指offer:判断二叉树是不是平衡二叉树
- 网络流24题之五 圆桌问题 最大匹配