zrq495
www.zrq495.com
水题~
Problem Description
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.
 

 

Output
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.
 

 

Sample Output
n e
- -----------
0 1
1 2
2 2.5
3 2.666666667
4 2.708333333
 1 #include<stdio.h>
2
3 __int64 func(int n)
4 {
5 int i, s=1;
6 if (n == 0)
7 return 1;
8 else
9 {
10 for (i=1; i<=n; i++)
11 {
12 s*=i;
13 }
14 return s;
15 }
16 }
17
18 int main()
19 {
20 int i, j;
21 double e;
22 printf("n e\n");
23 printf("- -----------\n");
24 printf("0 1\n");
25 printf("1 2\n");
26 printf("2 2.5\n");
27 for (i=3; i<=9; i++)
28 {
29 e=0;
30 for (j=0; j<=i; j++)
31 {
32 e+=1.0/func(j);
33 }
34 printf("%d %.9lf\n", i, e);
35 }
36 return 0;
37 }
posted on 2012-02-25 20:57  zrq495  阅读(206)  评论(0编辑  收藏  举报