一、理论证明
由以上推导易得公式为:Xk+1 = (Xk +a/Xk)/2
代码实现:
class Solution { public: int mySqrt(int x) { double last_pre = 3.000; for(int i = 0;i < 32;i++){ double cur_num = (pre_num + double(x)/pre_num)/2.0000; last_num = cur_num; } return last_num; } };
一、理论证明
由以上推导易得公式为:Xk+1 = (Xk +a/Xk)/2
代码实现:
class Solution { public: int mySqrt(int x) { double last_pre = 3.000; for(int i = 0;i < 32;i++){ double cur_num = (pre_num + double(x)/pre_num)/2.0000; last_num = cur_num; } return last_num; } };
转载于:https://www.cnblogs.com/jake9402/p/7572122.html