1. 程式人生 > >用e=1/1!+1/2!+1/3!+……公式求e的近似值,直到發現某一項的值小於10^(-5)為止;

用e=1/1!+1/2!+1/3!+……公式求e的近似值,直到發現某一項的值小於10^(-5)為止;

 #include<stdio.h>
#include<math.h>
int main()
{
int n=1;
float e=1,t=1,f=1;
do{
f=f*n;
t=1/f;
e=e+t;
n++;
}while (t>=1e-6);
printf("e=%f\n",e);
return 0;
}