#include<stdio.h>
#include<conio.h>
#include<math.h>
#define E 0.001
float f (float x)
{
return (cos(x)-(x*exp(x)));
}
void main()
{
int ctr,temp,ctr1;
float res,res1;
int p,NO;
float X1=0.00,X2=0.00;
float X3,FX1,FX2,FX3;
int co[10];
clrscr();
//For Scanning X1 and X2
printf("\nEnter the Roots:1::");
flushall();
scanf("%f",&X1);
printf("\nEnter the Roots:2::");
flushall();
scanf("%f",&X2);
ctr1=0;
clrscr();
printf("\n==========================================================");
printf("\nNO\tX1\tFX1\tX2\tFX2\tX3\tFX3");
printf("\n==========================================================");
do
{
FX1=FX2=FX3=0;
FX1 = f(X1);
FX2 = f(X2);
X3=((X1*FX2)-(X2*FX1))/(FX2-FX1);
FX3 = f(X3);
printf("\n%d\t%.4f\t%.4f\t%.4f\t%.4f\t%.4f\t%.4f",ctr1+1,X1,FX1,X2,FX2,X3,FX3);
X1=X2;
FX1=FX2;
X2=X3;
FX2=FX3;
ctr1++;
}while(fabs(FX3)>=E );
printf("\n\n%.4f",X3);
getch();
}