The method you use looks like it would work better passing 3 numbers.
or else changing
#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
Title | # Comments | Views | Activity |
---|---|---|---|
Convert image to byte array | 8 | 189 | |
How to configure Digital Ouput in Renesas RH850/FIL Micrcontroller ? | 5 | 185 | |
Inorder binary search tree | 5 | 158 | |
Finding a good hash function | 4 | 120 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
15 Experts available now in Live!