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.
Example
Output
n e
- -----------
0 1
1 2
2 2.5
3 2.666666667
4 2.708333333
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<stdio.h> 2 double fun(int i) 3 { 4 double re=2.5,to=6; 5 int n; 6 for(n=3;n<=i;n++) 7 { 8 re+=1/to; 9 to*=(n+1); 10 } 11 return re; 12 } 13 14 int main() 15 { 16 int i; 17 printf("n e "); 18 printf("------ "); 19 printf("0 1 1 2 2 2.5 "); 20 for(i=3;i<=9;i++) 21 printf("%d %.9lf ",i,fun(i)); 22 return 0; 23 }