+ 2
Find the square root of any positive integer without using built in functions like sqrt (), pow () etc... Using c++.
Post please.
2 Respuestas
+ 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;
}