c++求解自然对数e=1+1/1!+1/2!+…+1/n!的值#includeusing namespace std;int main(){int factorial(int n);int e=1,n=1;while(1/factorial(n)>1e-6){e=e+1/factorial(n);n++;}cout
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/28 23:49:42
c++求解自然对数e=1+1/1!+1/2!+…+1/n!的值#includeusing namespace std;int main(){int factorial(int n);int e=1,n=1;while(1/factorial(n)>1e-6){e=e+1/factorial(n);n++;}cout
c++求解自然对数e=1+1/1!+1/2!+…+1/n!的值
#includeusing namespace std;int main(){int factorial(int n);int e=1,n=1;while(1/factorial(n)>1e-6){e=e+1/factorial(n);n++;}cout
c++求解自然对数e=1+1/1!+1/2!+…+1/n!的值#includeusing namespace std;int main(){int factorial(int n);int e=1,n=1;while(1/factorial(n)>1e-6){e=e+1/factorial(n);n++;}cout
#include<iostream>
using namespace std;
int main()
{
double factorial(double n);
double e = 1, n = 1;
while((1.0 / factorial(n)) > 1e-6)
{
e = e + 1.0 / factorial(n);
n++;
}
cout<<e<<endl;
return 0;
}
double factorial(double n)
{
int i;
double s=1.0;
for(i=1; i<=n; i++)
s = s * i;
return s;
}
需要用double来储存.