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

Question #17834
Write a function that calculates the square root of a
number
1
Expert's answer
2012-11-06T10:24:12-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS