用do-while语句编写程序,计算e≈1+1/1!+1/2!+...+1/n!
用do-while语句编写程序,计算e≈1+1/1!+1/2!+...+1/n!
日期:2017-12-17 21:45:18 人气:2
#include
int main(){
double t=1,term,sum=1.0;
int i=1;
do{
t=t*i;term=1.0/t;
sum=sum+term;
i++;
} while(term>1e-12);
printf("e=%.12lf\n",sum);
return 0;
}
输出 e=2.718281828459