U calculate E
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 13241 accepted submission (s): 5725
Problem descriptiona 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.
Outputoutput
The approximations of E generated by the above formula for the values
Of N from 0 to 9. The beginning of your output shoshould appear similar
That shown below.
Sample outputn E
------------
0 1
1 2
2 2.5
3 2.666666667
4 2.708333333
Source greater New York 2000
1 // note the output format
2 # include <stdio. h>
3 # include <string. h>
4 # include <stdlib. h>
5
6
7 int DP [100];
8 double sum [100];
9
10
11 void fun (int n)
12 {
13 int I;
14
15 DP [0] = 1;
16
17 For (I = 1; I <= N; I ++)
18 DP [I] = DP [I-1] * I;
19
20}
21
22 int main ()
23 {
24 int I, j, N;
25 memset (DP, 0, sizeof (DP ));
26 memset (sum, 0, sizeof (SUM ));
27 fun (10 );
28 sum [0] = 1;
29 for (I = 1; I <= 9; I ++)
30 sum [I] = sum [I-1] + 1.0/dp [I];
31 printf ("n e \ n------------ \ n ");
32 For (I = 0; I <= 9; I ++ ){
33 If (sum [I] = (INT) sum [I])
34 printf ("% d \ n", I, INT (sum [I]);
35 else if (I = 2)
36 printf ("% d %. 1lf \ n", I, sum [I]);
37 Else
38 printf ("% d %. 9lf \ n", I, sum [I]);
39}
40 return 0;
41}