![]() |
#2
rjsp2017-11-10 11:16
|

include<iostream>
using namespace std;
#include<cmath>
void main()
{
int x=1;
float n=1.0,t=1,sum=0;
do{
t=1/n;
sum+=t;
n=n*(x++);
}while((fabs(t))>1e-6);
cout<<"e="<<sum<<endl;
}
一开始写出来运行出结果了,2.71828.后来细想SUM初值应该为1啊,求解[附件]1[附件]1using namespace std;
#include<cmath>
void main()
{
int x=1;
float n=1.0,t=1,sum=0;
do{
t=1/n;
sum+=t;
n=n*(x++);
}while((fabs(t))>1e-6);
cout<<"e="<<sum<<endl;
}
只有本站会员才能查看附件,请 登录