用迭代法求立方根的C++代码
时间: 2023-10-31 12:06:36 浏览: 182
迭代法求立方根.cpp
```
#include <stdio.h>
double cube_root(double x) {
double low = 0.0, high = x, mid;
while (high - low > 1e-9) {
mid = (low + high) / 2;
if (mid * mid * mid > x) {
high = mid;
} else {
low = mid;
}
}
return low;
}
int main() {
double x;
printf("请输入一个实数:");
scanf("%lf", &x);
printf("%.6lf 的立方根是:%.6lf\n", x, cube_root(x));
return 0;
}
```
阅读全文