** Write a program to find the root of a given equation by using False Position Method.
(x3 – 2x – 5 = 0) .
Answer:
#include<stdio.h>
main()
{
double y1,y2,x,c=0.0001,a,b,y3,y4;//c is
the accuracy of the program
printf("Please enter the two number
for finding root in false position method\n");
scanf("%lf %lf",&a,&b);
y1=a*a*a-2*a-5;y2=b*b*b-2*b-5;
if(y1<0&&y2>0)
{
if((y1*y2)>0)
printf("There is no root between
the two number");
else
{
do
{
x=((a*y2)-(b*y1))/(y2-y1);
y3=x*x*x-2*x-5;
if(y3<0)
a=x;
else
b=x;
}
while((b-a)>c);
printf("The root is
=%lf",x);
}
}
else if(y1>0&&y2<0)
{
y1=b*b*b-2*b-5; y2=a*a*a-2*a-5;
if((y1*y2)>0)
printf("There is no root between
This two number");
else
{
do
{
x=((b*y2)-(a*y1))/(y2-y1);
y4=(x*x*x)-2*x-5;
if(y4<0)
b=x;
else
a=x;
}
while((a-b)>c);
printf("This is the root
=%lf",x);
}
}
else
printf("There ti no root between this
two number");
printf("Thanks");