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.代码:
1 #include "stdio.h" 2 //#include "stdlib.h" 3 int main() 4 { 5 int tmp=1; 6 double sum=1; 7 int i=0; 8 printf("n e "); 9 printf("- ----------- "); 10 printf("%d %.10g ",i,sum); 11 for(i=1;i<10;i++) 12 { 13 tmp*=i; 14 sum+=(double)1/tmp; 15 printf("%d %.10g ",i,sum); 16 } 17 //system("pause"); 18 return 0; 19 }