WSQ 10 Babylonian method!

babylonianHey everyone!

This is my code to get the square root of a number using the babylonian method; it works with a do loop.

First of all, as always you need to know what your main needs to project, after that you can proceed to do your functions.

In my function called BM (babylonian method) consists in two doubles and one constant (a double is a kind of float that can handle mor digits), after that I wrote down the babylonian method formula in a loop, so it gives me the exact result of the square root, to have some fun, I made the give me all the guesses that the calculation is making, until the difference is less than the constant. You can see it on the terminal on «current guess».

Don´t forget that the square roots of negative numbers doesn´t exist, so you need to convert it to an absolute value.

Thanks! If you have any question please let me know in a comment.

Deja un comentario

Crea un blog o un sitio web gratuitos con WordPress.com.

Subir ↑