OpenJudge/Poj 1517 u Calculate e

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=;
double sum=;
int i=;
printf("n e\n");
printf("- -----------\n");
printf("%d %.10g\n",i,sum);
for(i=;i<;i++)
{
tmp*=i;
sum+=(double)/tmp;
printf("%d %.10g\n",i,sum);
}
//system("pause");
return ;
}
上一篇:如何在默认Python版本之间动态切换?


下一篇:python笔记之字符串