对原有的程序作了修改,请注意比对程序的区别:
#include
#include
int main()
{
int j,n=2;
double sin,t=1.0,x,s,p=1.0;
printf("input 实数x:");
scanf("%lf",&x);
s=x;
j=1;
sin=x;
while(fabs(p)>=1e-5)
{ j=j+1;
s=-s*x*x;
t=t*n*(n+1);
p=s/t;
sin=sin+p;
n=n+2;
}
printf("%f\n",sin);
printf("%d\n",j);
return 0;
}
t=1;
s=1;
t没有初值啊