1012

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 11 22 2.53 2.6666666674 2.708333333
 

 

Source
 

 

Recommend
JGShining
1 //控制输出
2  
3  /*Description: to
4 *
5 * Author: Vincent
6 *
7 * Date:2010/04/
8 * Contact:agilely@126.com
9 * Zju CS Lab
10 */
11 #include <iostream>
12  using namespace std;
13
14  #define MAX 1000
15
16  int main()
17 {
18 int ca,i=1;
19 double e=1;
20 cout<<"n e"<<endl<<"- -----------"<<endl;
21 cout<<"0 1"<<endl<<"1 2"<<endl<<"2 2.5"<<endl;
22 cout.setf(ios::fixed);
23 cout.precision(9);
24 for(ca=1;ca<10;ca++)
25 {
26 i*=ca;
27 e+=1.0/i;
28 if(ca>2)
29 cout<<ca<<" "<<e<<endl;
30 }
31 return 0;
32 }
33
34
35  

 

posted @ 2010-04-15 22:01  にんじゃ  阅读(122)  评论(0)    收藏  举报