here is the code that I have so far and I can not seem to get it to work properly it is return 1 for any number that is entered. Any help that you can give me would be greatly appreciated. Thanks
#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;
//x(n+1) = 1/2( x(n) + a / x(n) )
//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);
}