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
Title | # Comments | Views | Activity |
---|---|---|---|
SQL Statment to match two tables in c# | 6 | 74 | |
C++ check and remove last word from a string | 5 | 118 | |
Inorder binary search tree | 5 | 153 | |
Arduino EDI - Programming language | 3 | 62 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
20 Experts available now in Live!