Professional Documents
Culture Documents
Algorithm
Algorithm
com/problems/sqrtx/
Given a non-negative integer x, compute and return the square root of x.
Since the return type is an integer, the decimal digits are truncated, and only the
integer part of the result is returned.
int mySqrt(int x) {
double xn = 5;
for(int i=0; i<500; i++){
xn = 0.5*(xn + x/xn);
}
return (int)xn;
}