One of the easiest WSQ in this course, in only one thing that was hard to understand was how the babylonian method works.

In this page, I unsderstood how the method works, but only by an aritmethic way: http://pensamiento-matematico.blogspot.mx/2013/05/metodo-babilonico-de-resolucion-de.html Ize

I didn’t know how to put that through C++, it was obvious that in the function I needed to use a loop, so I decided to check out some friends wsq13 code. I felt like an useless guy when I saw it, it was too easy.

while ((raiz-x/raiz)/2>0.000001)
{
raiz=(raiz+x/raiz)/2;
}

The variables raiz & x are the base and height of the square that is the number that the users put in the main programm. Through the while loop these variables were going to be equalized, getting the media of the two variables at the same time, only one of these variables changes every loop and gets the value of the media. When the difference between the value that changes every loop and the division between the square and that same number gets close to zero, the loop stops and returns the value of the integer that was changing.

Here is the code link to GitHub: https://github.com/hrglez/TC1017/blob/master/WSQ13%20-%20Babylonian%20Square%20RootWSQ13

 

CC BY 4.0 #WSQ13 by tonygarciavz is licensed under a Creative Commons Attribution 4.0 International License.