1. 程式人生 > >使用近似公式計算e的值

使用近似公式計算e的值

e=1+1/1!+1/2!+1/3!+…+1/n!+…,使答案與標準答案誤差小於1e-5

程式碼如下:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i;
    double e,t;
    for(e=t=i=1;t>1.0e-5;e+=t/=i++);
    printf("e ≈ %g\n",e);
}