/* File name 7-2.c */ #include <stdio.h> #include <math.h> #define EPSILON 1.0E-10 double fun(double x); main() { double a=0.0; /* The initial value. */ double b=1.0; double c=(a+b)/2.0; while (fabs((a-b)/c)>EPSILON){ if (fun(c) == 0.0) break; /* c is the root */ else if (fun(a)*fun(c) > 0.0 ){ /* The root is between b and c. */ a=c; } else { /* The root is between a and c. */ b=c; } c= (a+b)/2.0; } printf("The root is about %1.10f\n.", c); } double fun(double x) { return x*x*x*x*x+x-1; }