您的位置:首页 > 其它

HDU 1008 u Calculate e

2016-07-03 22:52 169 查看
[align=left]Problem Description[/align]
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.

[align=left]Output[/align]
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.

[align=left]Sample Output[/align]

n e
- -----------
0 1
1 2
2 2.5
3 2.666666667
4 2.708333333

[align=left]Source[/align]
Greater New York 2000

简单题

#include<stdio.h>
int fact(int n)
{
int res=1;
while(n>=1)
{
res*=n;
n--;
}
return res;
}
int main()
{
printf("n e\n- -----------\n0 1\n1 2\n2 2.5\n3 2.666666667\n4 2.708333333\n");
int n,i;
double e;
for(n=5;n<=9;n++)
{
e=0.0;
for(i=0;i<=n;i++)
{
e+=1.0/double(fact(i));
}
printf("%d %.9lf\n",n,e);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: