#include <stdio.h>
#include <conio.h>
#include <math.h>
#define F(x) ( x*x*x - 2*x + 1 )
#define G(x) ( ( x*x*x + 1 ) / 2 )
#define EPS 0.00005
main()
{
int i, n;
float 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++)
{
x1 = G(x0);
printf("\n Iter. %d \t\t Xn = %f \t\t Xn+1 = %f", i, x0, x1);
e = fabs( (x1 - x0) / x1 );
if( e < EPS )
break;
x0 = x1;
}
if( e <= EPS )
printf("\n\n Root = %f", x1);
else
printf("\n\n INSUFFICIENT ITERATIONS ");
getch();
}
Output