Click here to Skip to main content
15,902,918 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to make a program of square root without including library
Posted

Hi

Try the below code

// Square root approximation - Babylonian method
double sqroot(const double s) {

double xn = s / 2.0;
double lastX = 0.0;

// Looping this way ensures we perform only as many calculations as necessary.
// Can be replaced with a static for loop if you really want to.
while(xn != lastX) {
lastX = xn;
xn = (xn + s/xn) / 2.0;
}

return xn;
}

 
Share this answer
 
Have a look at http://en.wikipedia.org/wiki/Methods_of_computing_square_roots
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900