Your task is to calculate the square root of a given number.
- Try to avoid using the pre-existing math libraries of your language.
- As input you'll be given a positive whole number, i.e. 1, 2, 3, 4…
- You are only required to handle cases where the result is a positive whole number.
Some potential approaches:
- Linear or binary search for a number that gives the input number when squared.
- Successive approximation using Newton's or Heron's method.
- Calculating one digit at a time or one bit at a time.
You can check out the Wikipedia pages on integer square root and methods of computing square roots to help with choosing a method of calculation.