tctony

Focus on linux,emacs,c/c++,python,algorithm...

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  17 随笔 :: 0 文章 :: 7 评论 :: 0 Trackbacks

u Calculate e

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1645    Accepted Submission(s): 696


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<iostream>
using namespace std;

int main() 
{
    
int f[10]={1,1,2},i;
    
double e[10]={1.0,2.0,2.5};
    printf(
"n e\n");
    printf(
"- -----------\n");
    printf(
"0 1\n");
    printf(
"1 2\n");
    printf(
"2 2.5\n");
    
for(i=3; i<10++i){
        f[i]
=f[i-1]*i;
        e[i]
=e[i-1]+1.0/f[i];
        printf(
"%d %.9lf\n",i,e[i]);
    }

    
return 0;
}

此题无甚,注意输出格式。
posted on 2007-11-29 08:15 tctony 阅读(600) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理