# Answer to Question #17834 in C++ for islam saad

Question #17834

Write a function that calculates the square root of a

number

number

Expert's answer

#include <iostream>

using namespace std;

double sqaure_root_of(double value)

{

double lo = 1.0;

double hi = value;

while( hi - lo > 0.00001)

{

double mid = lo + (hi -lo) / 2 ;

if( mid * mid - value> 0.00001)

{

hi = mid;

} else {

lo = mid;

}

}

return lo;

}

int main ()

{

cout<< sqaure_root_of(144)<< endl;

system("pause");

return0;

}

using namespace std;

double sqaure_root_of(double value)

{

double lo = 1.0;

double hi = value;

while( hi - lo > 0.00001)

{

double mid = lo + (hi -lo) / 2 ;

if( mid * mid - value> 0.00001)

{

hi = mid;

} else {

lo = mid;

}

}

return lo;

}

int main ()

{

cout<< sqaure_root_of(144)<< endl;

system("pause");

return0;

}

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment