// ROOT FINDING
// Program 3 : To impliment Newton Raphson Method

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

#define  F(x) ( 3*x - cos(x) - 1 )
#define dF(x) ( 3 + sin(x) )

#define EPS 0.00005

main()
{
	int i, n;
	double x0, x1, e;
	
	printf("\n Enter initial approx. root (x0) : ");
	scanf("%f", &x0);
	
	printf("\n Enter the no of max iterations : ");
	scanf("%d", &n);
	
	for( i=1; i<=n ; i++)
	{
		if( dF(x0) == 0 )
		{
			printf("\n dF(x) is zero.");
			break;
		}
		else
			x1 = x0 - ( F(x0)/dF(x0) );
			
		printf("\n Iter. %d \t Xn = %f   \t Xn+1 = %f", i, x0, x1);
		
		e = fabs( (x1-x0) / x0 );
		
		if( e < EPS )
			break;
		else	
			x0 = x1;
	}
	
	if( e <= EPS )
   		printf("\n\n Root = %f", x1);
   	else
  		printf("\n\n INSUFFICIENT ITERATIONS ");
	
	getch();
}



Output