68 282
Assignments Done
99,1%
Successfully Done
In November 2018

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

Question #17834
Write a function that calculates the square root of a
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;
}

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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions