#include<stdio.h>
#include<conio.h>
#include<math.h>
#define E 0.0001
float f(float t)
{
return((exp(-t))-t);
}
float df(float t)
{
return (-(exp(-t))-1);
}
void main()
{
int ctr,ctr1,po,ctr3;
float FX1=0.0,F_X=0.0;
float R1,X0,temp;
clrscr();
printf("\nEnter the Root::");
flushall();
scanf("%f",&R1);
X0=R1;
//Puting the value in f(x)
FX1 = f(R1);
//Putting the value in f!(x)
F_X = df(R1);
printf("\n==========================================================");
printf("\nNO\tX0\tFX1\tF_X");
printf("\n==========================================================");
ctr3=0;
do
{
F_X=FX1=0;
F_X = df(X0);
FX1 = f(X0);
temp=X0;
X0 = X0 - (FX1/F_X);
printf("\n%d\t%.4f\t%.4f\t%.4f\n",ctr3+1,X0,FX1,F_X);
ctr3++;
}
while((fabs(temp-X0))>=E);
printf("\n%.4f",X0);
getch();
}
/***********************************OUTPUT*********************************
Enter the Root::0.5
==========================================================
NO X0 FX1 F_X
==========================================================
1 0.5663 0.1065 -1.6065
2 0.5671 0.0013 -1.5676
3 0.5671 0.0000 -1.5671
0.5671
/******************************************************************************/