练习2-5-7:求e的近似值(多分支结构,简单循环结构)

#include

#include

int main()

{

    int n,i,k;

    double a,e;

    e=1;

    scanf("%d",&n);

    if(n>=1)

    {

        for(i=1;i<=n;i++)

        {

            a=1;

            for(k=i;k>0;k--)

            {

                a=a*k;

            }

            e=e+(1/a);

        }

        printf("%.12lf",e);

    }

    else

        printf("input error!");

    return 0;

}

你可能感兴趣的:(练习2-5-7:求e的近似值(多分支结构,简单循环结构))