1.用途:求平方根
2.实现:
1 int NewtonSqrt(int x){ 2 double xi, x0 = x, C = x; 3 if (!x) return 0; 4 while (1){ 5 xi = 0.5 * (x0 + C / x0); 6 if (fabs(x0 - xi) < 1e-7) break; 7 x0 = xi; 8 } 9 return x0; 10 }
3.参考资料:
https://www.cnblogs.com/houkai/p/3332520.html
https://leetcode-cn.com/problems/sqrtx/solution/