

REGULA-FALSI METHOD
//Solve by Regula falshi method correct upto 3 decimal places. 2x-log10(x)-7=0
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
float f(float x)
{
return(2*x-log10(x)-7.0);
}
int main()
{
float a,b,h,x,y,err;
int n=0,d;
printf("Enter the lower limit: ");
scanf("%f",&a);
printf("\nEnter the upper limit: ");
scanf("%f",&b);
if(f(a)*f(b)>0)
{
printf("\nRoot does not exists between %f and %f\n",a,b);
exit(0);
}
if(f(a)<0&&f(b)>0)
{
y=b;
b=a;
a=y;
}
printf("\nEnter the correction upto decimal place: ");
scanf("%d",&d);
err=(5.0/pow(10,d));
printf("\n\nIte-no \tAn(+ve) \tBn(-ve) \t f(An) \t\t f(Bn) \t\t Hn \t\t Xn+1 \t\tf(Xn+1)\n");
printf("\n--------------------------------------------------------");
printf("--------------------------------------------------------\n");
x=0;
do
{
y=x;
h=fabs(f(a))/(fabs(f(a))+fabs(f(b)));
x=a+h*(b-a);
printf("\n %2d \t%2.5f \t%2.5f \t%2.5f \t%+2.5f \t%2.5f \t%2.5f \t%+2.5f\n",++n,a,b,f(a),f(b),h,x,f(x));
if(f(x)>0)
a=x;
else
b=x;
}while(fabs(x-y)>=err);
printf("\n\n\t\t\t\t\tThe root is: x=%f\n\n\n",x);
return 1;
}
