long isqrt(long x)
{
long i = 1, result = 1;
// Base cases
if(x == 0 || x == 1)
return x;
// Staring from 1, try all numbers until
// i * i is greater than or equal to x.
while (result <= x)
{
i++;
result = i * i;
}
return i - 1;
}
void main()
{
c.fwrite("isqrt(100) = %d\n", isqrt(100));
c.fwrite("isqrt(144) = %d\n", isqrt(144));
c.fwrite("isqrt(1296) = %d\n", isqrt(1296));
c.fwrite("isqrt(2500) = %d\n", isqrt(2500));
}
OUTPUT
isqrt(100) = 10
isqrt(144) = 12
isqrt(1296) = 36
isqrt(2500) = 50