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.
 
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
");
11     printf("- ");
12     for(int i=1;i<=11;i++) printf("-");
13     printf("
");
14     printf("0 1
");
15     printf("1 2
");
16     printf("2 2.5
");
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
",ans);
27     }
28     return 0;
29 }
代码


作者:乌鸦坐飞机
出处:http://www.cnblogs.com/whistle13326/
新的风暴已经出现 怎么能够停止不前 穿越时空 竭尽全力 我会来到你身边 微笑面对危险 梦想成真不会遥远 鼓起勇气 坚定向前 奇迹一定会出现

 
原文地址:https://www.cnblogs.com/whistle13326/p/7155839.html