您的位置:首页 > 运维架构

OpenJudge/Poj 1517 u Calculate e

2014-02-20 22:06 453 查看
1.链接地址:
http://bailian.openjudge.cn/practice/1517 http://poj.org/problem?id=1517
2.题目:

总时间限制:1000ms内存限制:65536kB描述A simple mathematical formula for e is
e=Σ0<=i<=n1/i!
where
n is allowed to go to infinity. This can actually yield very accurate
approximations of e using relatively small values of n.输入No input输出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.样例输入
no input

样例输出
n e
- -----------
0 1
1 2
2 2.5
3 2.666666667
4 2.708333333
...

来源Greater New York 2000

3.思路:

4.代码:

#include "stdio.h"
//#include "stdlib.h"
int main()
{
int tmp=1;
double sum=1;
int i=0;
printf("n e\n");
printf("- -----------\n");
printf("%d %.10g\n",i,sum);
for(i=1;i<10;i++)
{
tmp*=i;
sum+=(double)1/tmp;
printf("%d %.10g\n",i,sum);
}
//system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: