早教吧 育儿知识 作业答案 考试题库 百科 知识分享

十万火急!浙大OJ1113uCalculateeWA坐等大侠指点ProblemDescriptionAsimplemathematicalformulaforeiswherenisallowedtogotoinfinity.Thiscanactuallyyieldveryaccurateapproximationsofeusingrelativelysmallvaluesofn

题目详情
十万火急 !浙大OJ 1113 u Calculate e WA 坐等大侠指点
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
这是我的代码
#include
int main()
{
int n,b;
double e=2.00,a=1.00;
printf("n e\n");
printf("- -----------\n");
for(n=0;n=2)
{
a=a/n;
e=e+a;
}
if(n==2)
printf("%.1lf",e);
else
printf("%.9lf\n",e);
}
return 0;
}
▼优质解答
答案和解析
#include
int main()
{
int n,b;
double e=2.00,a=1.00;
printf("n e\n");
printf("- -----------\n");
for(n=0;n=2)
{
a=a/n;
e=e+a;
}
if(n==2)
printf("%.1lf\n",e);
else
printf("%.9lf\n",e);
}
//scanf("%*d");
return 0;
}