Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Returns floor of square root of x
- int ft_sqrt(int x)
- {
- // 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.
- int i = 1, result = 1;
- while (result <= x)
- {
- i++;
- result = i * i;
- }
- return i - 1;
- }
Add Comment
Please, Sign In to add comment