欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

HDU 1012 u Calculate e

程序员文章站 2022-07-15 08:51:05
...

传送门:HDU 1012

#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int multiply[15];
    double summul[15];
    multiply[0] = 1;
    summul[0] = 1;
    for(int i=1;i<10;i++)
    {
        multiply[i] = multiply[i-1]*i;
        summul[i] = summul[i-1]+1/(double)multiply[i];
    }
    printf("n e\n");
    printf("- -----------\n");
    printf("0 1\n");
    printf("1 2\n");
    printf("2 2.5\n");
    for(int i = 3;i<10;i++)
        printf("%d %.9lf\n",i,summul[i]);
    return 0;
}
#include <iostream>
#include <cstdio>

using namespace std;

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


相关标签: hdu ACM