//計(jì)算x-1/2*x^3/4+1/2*3/4*x^5/6-1/2*3/4*5/6*x^7/8+……的近似值,直到最后一項(xiàng)的絕對(duì)值小于eps
#?include<stdio.h>
#?include<math.h>
#?define?eps?0.001
int?main()
{
int?n=2;
double?t,s,x;
printf("請(qǐng)輸入x的值");
scanf("%lf",&x);
t=x,s=t;
while(fabs(t)>eps)
{
t=-t*(2*n-3)*x*x/(2*n-2);
s=s+t/(2*n);
n++;
}
printf("%f\n",s);
return?0;
}
//可以計(jì)算當(dāng)x<=1時(shí)的值,但當(dāng)x>1時(shí)運(yùn)行就沒有結(jié)果了,這是怎么回事?
- 2 回答
- 0 關(guān)注
- 1601 瀏覽
添加回答
舉報(bào)
0/150
提交
取消