// ROOT FINDING
// Program 2 : To impliment Regula Falsi 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      \t F(X)");
  	
  	for( i=1; i<=n ; i++)
  	{
		x = ( a*F(b) - b*F(a) ) / ( F(b) - F(a) );
		
		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