1、 用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;
}
#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;
}