// ROOT FINDING
// Program 1 : To impliment Bisection Method

#include <stdio.h>
#include <conio.h>
#include <math.h>

#define F(x) ( 3*x + sin(x) - exp(x) )

#define EPS 0.00005

main()
{ 
	int i, n;
  	double a, b, x;
	double xl, e; //xl is used to store last value of x to calculate e
  	
  	a = 0;
  	b = 1;
  	
  	printf("\n Enter the no of total iterations : ");
  	scanf("%d", &n);
  	
  	printf("\n Iter. \t A \t\t B \t\t X=(A+B)/2 \t F(X)");
  	
  	for( i=1; i<=n ; i++)
  	{
		x = ( a + b ) * 0.5;
		
		printf("\n  %2d \t %f \t %f \t %f \t %f", i, a, b, x, F(x));
		
		if( F(x)*F(a) < 0 )
			b = x;
		else
			a = x;
			
		e = fabs( (xl - x) / xl );
		
		if( e < EPS )
			break;
			
		xl = x;
	}
	
	if( e <= EPS )
   		printf("\n\n Root = %f", x);
   	else
  		printf("\n\n INSUFFICIENT ITERATIONS ");
  	
  	getch();
}



Output