Correct Output For Square root Integer


#1

public static int Sqrt(int A)
{
long ans = 0;
long start = 0;
long end = A;

while( start <= end )
{
long mid = (start + mid)/2;
if( mid * mid = A)
{
ans = mid;
}
else if( mid * mid < A)
{
start = mid +1;
ans = mid;
}
else
{
end = mid -1;
}
return (int)ans;
}