#include #include #define EPSILON 0.0001 double function(double x) { return pow(x, 3) - x - 2; } void bisection(double a, double b, double epsilon) { int i = 1; double c, fc; printf("=============================================\n"); printf("Step\ta \t b \t c \t f(c)\n"); while ((b - a) >= epsilon) { c = (a + b) / 2.0; fc = function(c); printf("%-5d %-8.5f %-8.5f %-8.5f %- 8.7f\n", i, a, b, c, fc); if (fc == 0.0) break; else if (fc * function(a) < 0) b = c; else a = c; i++; } printf("\nThe value of root is: %.10f with % 2.4f precision\n", c, epsilon); printf("=============================================\n"); } int main() { double a = 1.0; // Initial guesses double b = 2.0; bisection(a, b, EPSILON); return 0; }