hdoj1012--u Calculate e
2014-02-28 11:41
316 查看
[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
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
#include<iostream> #include <iomanip> using namespace std; int main() { int i,n; double s,t; cout<<"n e"<<endl; cout<<"- -----------"<<endl; cout<<"0 1"<<endl; cout<<"1 2"<<endl; cout<<"2 2.5"<<endl; s=2.5; n=2; for(i=3; i<=9; i++) { n=i*n; s+=1.0/n; cout<<i<<" "<<fixed<<setprecision(9)<<s<<endl; } return 0; }
相关文章推荐
- JS中的prototype[转载]
- MongoDb企业应用实战(一) 写在MongoDB应用介绍之前(ii)
- SCCM2012R2部署之三:SQL Server 2012数据库准备
- 在CentOS/RHEL 6.5上安装Chromium
- 还在为电脑开机速度慢而烦恼
- 无头单链表删除一个节点
- 映射本地web服务到公网
- Android应用开发之(如何自动在桌面创建快捷方式)
- 深入解读Linux与Android的相互关系(转-lining)
- 【翻译】自定义 UIViewController Transitions
- 94. Binary Tree Inorder Traversal
- 启动和停止init.rc中的服务
- LibSVM分类的实用指南
- block语法详细讲解
- ApplicationContextAware得到ApplicationContext的原理
- ffmpeg处理rtmp直播流(截图、收录)
- C#调用WIN32 的API函数--USER32.DLL
- 使用memcached显著提升站点性能
- 进程与线程的一个简单解释
- java中使用static