Here is a simple program to compute cube roots.
Code:
#include <stdio.h>
#include <math.h>
int main()
{
double x, r=1, rr=0, hi, lo=0, count=0;
printf ("Enter a number to find the cube root:\n");
scanf("%d", &x);
hi=x;
while ( fabs(rr-x) > 0.01)
{
count+=1;
printf("count = %g\n", count);
r=(hi+lo)/2;
rr=pow(r,3);
if (rr > x)
hi=r;
if (rr < x)
lo=r;
}
printf("The cube root of %d is:\n%d\n", x, r);
return 0;
}
For some reason my 'while' loop does not seem to execute. Can anyone tell me why this happens? Below is the output of the program
Code:
$ ./a.out
Enter a number to find the cube root:
88
The cube root of 88 is:
134514048
$