• hdu 1012 u Calculate e


    u Calculate e

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


    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
     
    Recommend
    JGShining   |   We have carefully selected several similar problems for you:  1032 1022 1071 1006 1048 
     
    这道题没有输入,开始看到的时候怎么看怎么觉得怪异~题目不难,读懂题就好,注意输出,前三个数的输出后后面的输出不同。
     
    题意:按题目给的公式,输出n从0到9的结果,前3个lg输出,后面的保留9位小数。
     
    附上代码:
     1 #include <stdio.h>
     2 double add(double t)
     3 {
     4     double s=1;
     5     int i;
     6     if(t==0)   //0!=1
     7         return 1;
     8     for(i=1; i<=t; i++)  //求n!
     9         s*=i;
    10     return s;
    11 }
    12 int main()
    13 {
    14     double e=0;
    15     int i,j;
    16     printf("n e
    ");
    17     printf("- -----------
    ");
    18     printf("0 1
    ");
    19     for(i=1; i<=9; i++)
    20     {
    21         e=0;
    22         for(j=0; j<=i; j++)
    23             e=e+1/add(j);
    24         if(i<=2)              //输出需要分开讨论
    25             printf("%d %lg
    ",i,e) ; 
    26         else
    27             printf("%d %.9lf
    ",i,e) ;
    28     }
    29     return 0;
    30 }
  • 相关阅读:
    操作系统六文件管理
    Educational Codeforces Round 38 (Rated for Div. 2) ABCD
    51nod 1100 斜率最大
    51nod 最小方差
    51nod 1065 最小正子段和
    P1280 尼克的任务
    牛客小白月赛2
    Codeforces Round #210 (Div. 1) B 二分+dp
    江西财经大学第一届程序设计竞赛
    51nod 1596 搬货物
  • 原文地址:https://www.cnblogs.com/pshw/p/4760739.html
Copyright © 2020-2023  润新知