循环错误
为何这个程序运行结果相差太远!
# include <iostream.h>
# include <math.h> //求sinx的近似直!
void main()
{
int x;
cout<<"please input x:\n";
cin>>x;
int n=1;
double sum=0,sn=x; //sn是项
//求 x/1-x3/3!+x5/5!-x7/7!+....
while(fabs(sn)>=0.0000001)
{
sum+=sn;
n++;
sn*=(-x*x)/(n+n-1)/(n+n-2);
}
//我输入33(x=33)
cout<<sum<<endl; //输出的结果是4.9517e+011
cout<<sin(x)<<endl; //输出的结果是0.999912
}
请大家指点一下: