#include<stdio.h>
#include<conio.h>
#include<math.h>
#define epsil 0.00001
int p,c[10];
void appro();
voidfalse(float,float,float,float);
void main()
{
clrscr();
appro();
getch();
}
voidfalse(float x1,float x2,float fx1,float fx2)
{
float x3,fx3,temp;
int n=1;
if(fx1<0&&fx2>0||fx1>0&&fx2<0)
{
printf("******************************************************************\n");
printf("\nIt x1 fx1 x2 fx2 x3 fx3\n");
printf("******************************************************************\n");
do
{
temp=x3;
x3=(((x1*fx2)-(x2*fx1))/(fx2-fx1));
fx3=x3-exp(-x3);
if(fx3==0)
{
break;
}
if((fx1*fx3)>0)
{
x1=x3;
fx1=fx3;
}
else
{
x2=x3;
fx2=fx3;
}
printf("%d %.4f %.4f %.4f %.4f %.4f %.4f\n",n,x1,fx1,x2,fx2,x3,fx3);
n=n+1;
}while((fabs(temp-x3)>epsil)&&(fx3!=0));
printf("\n\t\t********************\n");
printf("\n\t\tThe root is %.4f\n",x3);
printf("\t\t********************\n");
}
else
{
clrscr();
printf("\nError in the Initial approximation\n ");
printf("\nPlease enter right approximation\n\n");
appro();
}
}
void appro()
{
float x1,x2,x3,fx1,fx2,fx3;
printf("\nPlease Enter first approximation: ");
scanf("%f",&x1);
printf("\nPlease Enter second approximation: ");
scanf("%f",&x2);
fx1=x1-exp(-x1);
fx2=x2-exp(-x2);
false(x1,x2,fx1,fx2);
}