对于求开方也就是求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;
}
对于求开方也就是求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;
}