You are on page 1of 1

https://leetcode.

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;
}

You might also like