牛顿迭代法
作者:互联网
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/
标签:xi,return,int,牛顿,https,迭代法,com,x0 来源: https://www.cnblogs.com/lvhui123/p/15902993.html