请朋友们帮我指点一下(谢谢):编C++程序求e的x次方的值执行相当怪异,
诺希亚 2009-02-13 10:06:39 e(x)=1+x(1)/1!+x(2)/2!+.....+x(n)/n!
编程求e(x)的值
#include<iostream>
#include<iomanip>
#include<cmath>
#include<fstream>
using namespace std;
int main()
{
double product=1,quotient=0,x=0,value=0;
ofstream outfile("C:\\out.OUT");
while(x>-1&&x<1)
{
outfile<<"Enter x: "<<endl;
cin>>x;
outfile<<"x="<<setprecision(2)<<x<<endl;
for(int n=1;n<=500;n++)
{
product*=n;
quotient=pow(x,n)/product;
value+=quotient;
}
value+=1;
outfile<<"the sum of e of the x-the power is "<<setprecision(5)<<fixed<<value<<endl;
}
outfile.close();
return 0;
}
结果输出为:
Enter x:
x=0.01
the sum of e of the x-the power is 1.01005
Enter x:
x=0.02
the sum of e of the x-the power is 2.01005
Enter x:
x=0.03
the sum of e of the x-the power is 3.01005
Enter x:
x=0.04
the sum of e of the x-the power is 4.01005
Enter x:
x=0.05
the sum of e of the x-the power is 5.01005
Enter x:
x=0.06
the sum of e of the x-the power is 6.01005
Enter x:
x=0.07
the sum of e of the x-the power is 7.01005
Enter x:
x=0.08
the sum of e of the x-the power is 8.01005
Enter x:
x=0.09
the sum of e of the x-the power is 9.01005
Enter x:
x=0.10
the sum of e of the x-the power is 10.01005
Enter x:
x=0.20
the sum of e of the x-the power is 11.01005
Enter x:
x=0.30
the sum of e of the x-the power is 12.01005
Enter x:
x=0.40
the sum of e of the x-the power is 13.01005
Enter x:
x=0.50
the sum of e of the x-the power is 14.01005
Enter x:
x=0.60
the sum of e of the x-the power is 15.01005
Enter x:
x=0.70
the sum of e of the x-the power is 16.01005
Enter x:
x=0.80
the sum of e of the x-the power is 17.01005
Enter x:
x=0.90
the sum of e of the x-the power is 18.01005
Enter x:
另一次输出为:
Enter x:
x=0.1
the sum of e of the x-the power is 1.10517
Enter x:
x=0.20
the sum of e of the x-the power is 2.10517
Enter x:
x=0.30
the sum of e of the x-the power is 3.10517
Enter x:
x=0.40
the sum of e of the x-the power is 4.10517
Enter x:
x=0.50
the sum of e of the x-the power is 5.10517
Enter x:
x=0.60
the sum of e of the x-the power is 6.10517
Enter x:
x=0.70
the sum of e of the x-the power is 7.10517
Enter x:
x=0.80
the sum of e of the x-the power is 8.10517
Enter x:
x=0.90
the sum of e of the x-the power is 9.10517
Enter x:
哪位朋友帮我指点一下,哪里出错了
非常感谢