1012 u Calculate e

A simple mathematical formula for e is

1012 u Calculate e

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
5 2.716666667
6 2.718055556
7 2.718253968
8 2.718278770
9 2.718281526
 
 #include<stdio.h>
int jc(int n)
{
int i=,s=;
if(n==||n==)
return ;
while(i<=n)
{
s*=i;
i++;
}
return s;//计算n!
}
int main()
{
double a[];
a[]=;
for(int i=;i<=;i++)
{
a[i]=1.0/jc(i)+a[i-];
}
printf("n e\n");
printf("- -----------\n");
for(int i=;i<=;i++)
{
if(i!=)
printf("%d %.10g\n",i,a[i]);
else
printf("%d %.9f\n",i,a[i]);
}
return ;
}
上一篇:jps command not found已解决


下一篇:ACM比赛学习指导(20180223)