求2的立方根的近似值(精确到0.01)用二分法,
问题描述:
求2的立方根的近似值(精确到0.01)用二分法,
答
int main(){
double a=1,b=2;
while (fabs(b-a)>0.01){
double c = (a+b)/2.0;
if ((2-a*a*a)*(2-c*c*c) b=c;
else
a=c;
}
printf("%8.3lg\n",(a+b)/2.0);
return 0;
}