f(x) = x**3 - n = 0
(x0, f(x0)) 处的切线与x轴交点(x1, 0)对应的f(x1) 会逐渐收敛到值为0处,即(f(x{n+1} ~ f(xn) ~ 0) ~ (x{n+1} ~ xn)
#include <iostream>
using namespace std;
int main()
{
double n;
cin >> n;
double x = n, eps = 1e-6;
while(true)
{
// x1 = x0 + f(x0)/f'(x0), 终止条件 abs(x{n+1} - xn) < epsion or abs(f(xn) - 0) < epsion, 即收敛
double fx = x*x*x - n;
double dfdx = 3*x*x;
double x1 = x - fx/dfdx;
if (abs(x1 - x) < eps) break;
x = x1;
}
printf("%.6lf\n", x);
return 0;
}