题解 | #求解立方根#
求解立方根
http://www.nowcoder.com/practice/caf35ae421194a1090c22fe223357dca
牛顿-拉弗森迭代法求解立方根:
#include<iostream> using namespace std; int main(){ double n; cin>>n; double x = 1; double next = x - (x*x*x - n) / (3*x*x); while(x - next > 0.000000001 || x - next < -0.000000001){ x = next; next = x - (x*x*x - n) / (3*x*x); } printf("%.1f\n", x); return 0; }