Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.
#include <stdio.h>
double square_root(double low, double high);
int main(void)
{
float number;
double root;
printf("Enter a number to compute the square root of.\n");
scanf("%f", &number);
root = square_root(1, number);
printf("The square root of %.3f is about %.3lf\n", number, root);
system("PAUSE");
return 0;
}
double square_root(double low, double high)
{
float mid;
mid = (high + low) / 2;
//Base Case
if((mid*mid) == high)
return mid;
//Stops when the high and low numbers are within 0.001 of one another.
if((high - low) < 0.001)
return mid;
if((mid*mid) > high)
return square_root(low, mid);
return square_root(mid, high);
}
<code edited out>
sunnycoder
ZAPE
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.