Guest User

Untitled

a guest
Nov 15th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. // Returns floor of square root of x
  2. int ft_sqrt(int x)
  3. {
  4. // Base cases
  5. if (x == 0 || x == 1)
  6. return x;
  7.  
  8. // Staring from 1, try all numbers until
  9. // i*i is greater than or equal to x.
  10. int i = 1, result = 1;
  11. while (result <= x)
  12. {
  13. i++;
  14. result = i * i;
  15. }
  16. return i - 1;
  17. }
Add Comment
Please, Sign In to add comment