HDU u Calculate e
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.
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
Source
看着有点吓人 但是很水 按照题目公式来就好了
1 /* 2 前三个数 直接打印就行 3 */ 4 #include<cstdio> 5 #include<iostream> 6 7 using namespace std; 8 9 int main() { 10 printf("n e\n"); 11 printf("- "); 12 for(int i=1;i<=11;i++) printf("-"); 13 printf("\n"); 14 printf("0 1\n"); 15 printf("1 2\n"); 16 printf("2 2.5\n"); 17 for(int i=3;i<=9;i++) { 18 double ans=.0,k=1; 19 int t=0; 20 printf("%d ",i); 21 for(int j=0;j<=i;j++) { 22 ans+=(1/k); 23 t++; 24 k*=t; 25 } 26 printf("%.9lf\n",ans); 27 } 28 return 0; 29 }
作者:乌鸦坐飞机
出处:http://www.cnblogs.com/whistle13326/
新的风暴已经出现
怎么能够停止不前
穿越时空 竭尽全力
我会来到你身边
微笑面对危险
梦想成真不会遥远
鼓起勇气 坚定向前
奇迹一定会出现