======================================================================
Progaram to find solutions to equations of the form f(x)=0 using
Bisection Method (Bolanzo method)
LANGUAGE : C (Compiler: GNU GCC)
=======================================================================
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
double func(double x){
double y;
y=x*exp(x)-1;
return y;
}
int main()
{
double xL,xH,e;
printf("Enter two real numbers between which the root is to be found\n");
scanf("%lf %lf",&xL,&xH);
printf("\nEnter the tolerance\n");
scanf("%lf",&e);
double xMid = (xL+xH)/2;
double prev_xMid;
do{
prev_xMid=xMid;
if(func(xL)*func(xMid)<0){
xH=xMid;
}
if(func(xL)*func(xMid)>0){
xL=xMid;
}
xMid=(xL+xH)/2;
}while(fabs((prev_xMid-xMid)/xMid)>e);
printf("\n Root is %lf ",xMid);
return 0;
}