早教吧作业答案频道 -->其他-->
编写程序计算 e^x=1+x+x^2/2!+x^3/3!+….+x^n/n!x^n/n!0; n++)x09{x09x09for (k = 1,i = 1,z = 1; i
题目详情
编写程序计算 e^x=1+x+x^2/2!+x^3/3!+….+x^n/n!x^n/n!0; n++)
\x09{
\x09\x09for (k = 1,i = 1,z = 1; i
\x09{
\x09\x09for (k = 1,i = 1,z = 1; i
▼优质解答
答案和解析
#include
#include
#include
using namespace std;
int main()
{
\x09double k,x, n, e, sum; //k换成double
\x09int i;
\x09sum = 1;
\x09e = 1;
\x09cout << "输入X的值" << endl;
\x09cin >> x;
\x09for (n = 1; n > 0; n++)
\x09{
\x09\x09for (k = 1, i = 1; i <= n; i++)
\x09\x09{
\x09\x09\x09k = k* i;
\x09\x09}
\x09\x09e = pow(x, n) / k;
\x09\x09sum = sum + e;
\x09\x09if (e < 0.000001)
\x09\x09\x09break;
\x09\x09
\x09}
\x09cout << setprecision(3) << "e^x=" << sum << endl;
\x09return 0;
}
#include
#include
using namespace std;
int main()
{
\x09double k,x, n, e, sum; //k换成double
\x09int i;
\x09sum = 1;
\x09e = 1;
\x09cout << "输入X的值" << endl;
\x09cin >> x;
\x09for (n = 1; n > 0; n++)
\x09{
\x09\x09for (k = 1, i = 1; i <= n; i++)
\x09\x09{
\x09\x09\x09k = k* i;
\x09\x09}
\x09\x09e = pow(x, n) / k;
\x09\x09sum = sum + e;
\x09\x09if (e < 0.000001)
\x09\x09\x09break;
\x09\x09
\x09}
\x09cout << setprecision(3) << "e^x=" << sum << endl;
\x09return 0;
}
看了 编写程序计算 e^x=1+x...的网友还看了以下: