hdu 1012 u Calculate e【数学水题】
2015-12-16 11:05
295 查看
u Calculate e
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 38462 Accepted Submission(s): 17414
[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
一道水题,循环就可以了,只是没注意,wa 了一次...
#include<stdio.h>
int main()
{
printf("n e\n");
printf("- -----------\n");
printf("0 1\n");
double e=1,tp=1;
for(int i=1;i<=9;++i)
{
tp*=i;
e+=1.0/tp;
if(i<=1)
{
printf("%d %.f\n",i,e);
}
else if(i<3)
{
printf("%d %.1f\n",i,e);
}
else
{
printf("%d %.9f\n",i,e);
}
}
return 0;
}
相关文章推荐
- Android对齐属性大全
- SQL Server 备份和还原全攻略
- response.getWriter().write()与out.print()的区别
- SVN各个字母代表的意思
- will-change属性
- js校验
- MongoDB安装、CURD操作、使用场景分析总结(1)
- 设计模式(十二)---策略模式
- 杭电ACM1907(Nim博弈)
- 数据模型
- Java实现http与https切换
- SQL Server 重复执行作业中某个步骤
- SQL Server 维护计划备份主分区
- 大数据之mongodb --> (1)在ubuntu上安装mongodb
- Unix/Linux文件系统剖析
- Java并发编程:线程间协作的两种方式:wait、notify、notifyAll和Condition
- 开发小计(1)
- 性能
- pat考试准备一_两个数字和的标准化输出
- git学习笔记-1