牛顿迭代法求开方

来源:互联网 发布:微信定位软件 编辑:程序博客网 时间:2024/06/05 18:05

对于求开方也就是求x^2=a的解,这里f(x)=x^2-a,f'(x)=2x

    int mySqrt(int x) {        double res=x;        while(abs(pow(res,2)-x)>0.0001)        {            res=(res+x/res)/2;        }        return res;    }


原创粉丝点击