+ 2

Find the square root of any positive integer without using built in functions like sqrt (), pow () etc... Using c++.

Post please.

28th Aug 2017, 7:51 AM
Quassarian Viper
Quassarian Viper - avatar
2 Respuestas
28th Aug 2017, 8:13 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 3
An easy one is the babylonian method! To find the square root of n the idea is to pick a guess G and then make the halfway point of G and n/G your new guess. double babylon(double n){ double guess = n / 2.; // 7 times is good enough, increase to whatever you think works best though. for(int i = 0; i < 7; i++){ guess = 0.5 * (guess + n / guess); } return guess; }
28th Aug 2017, 8:17 AM
Schindlabua
Schindlabua - avatar