#include<stdio.h>
#include<conio.h>
#include<math.h>
#define ESP 0.00001
#define F1(x) (x)*(x)*(x) - 5*(x) + 3
#define F2(x) 3*(x)*(x) - 5
void main()
{
float x1,x2,f1,f2;
clrscr();
do
{
printf("\nEnter the value of x1: ");
scanf("%f",&x1);
}while(F1(x1) > 0);
printf("\n______________________________________________\n");
printf("\n x1\t f(x)\t f'(x)\t x2");
printf("\n______________________________________________\n");
do
{
f1=F1(x1);
f2=F2(x1);
x2=x1-(f1/f2);
printf("\n%f %f %f %f ",x1,f1,f2,x2);
x1=x2;
getch();
}while(F1(x2)>ESP);
printf("\n______________________________________________\n");
printf("\n\nApp.root = %f",x2);
getch();
}
/*
OUT PUT
---------
Enter the value of x1: 1
______________________________________________
x1 f(x) f'(x) x2
______________________________________________
1.000000 -1.000000 -2.000000 0.500000
0.500000 0.625000 -4.250000 0.647059
0.647059 0.035620 -3.743945 0.656573
0.656573 0.000176 -3.706736 0.656620
______________________________________________
App.root = 0.656620
*/