Bisection Method

Source Code:

Write a program in C to find the root of the equation 𝒇(𝒙) = 𝒙𝟑 − 𝒙 − 𝟐 using the Bisection Method.

#include <stdio.h>
#include <conio.h>
double f(double x){ return x*x*x - x - 2; }
int main(){
 clrscr();
 double a=1, b=2, c;
 for(int i=0;i<20;i++){
c = (a+b)/2;
 if(f(a)*f(c)<0) b=c;
else a=c;
 }
 printf("\n\n root : %.4f\n", c);
 getch();
 return 0;
}

Output