TinyChan

New reply in topic: Wonder Woman (2017)

You are not recognized as the original poster of this topic.

:

You are required to fill in a captcha for your first 5 posts. Sorry, but this is required to stop people from posting while drunk. Please be responsible and don't drink and post!
If you receive this often, consider not clearing your cookies.

Please familiarise yourself with the rules and markup syntax before posting.


Replying to Anonymous E…

int sqrt (int n)

{

   return sqrt_helper(n, 1, n);

}

int sqrt_helper (int n, int min, int max)

{

   if (max < min) return -1; // no square root

   int guess = (min + max) / 2;
   if (guess * guess == n)

     {  // found it!

        return guess;

     }

else if (guess * guess < n)

     { // too low 

   return sqrt_helper (n, guess + 1, max); // try higher

     }

else

     { // too high

   return sqrt_helper (n, min,, guess - 1); // try lower

     }

}