C program to implement bisection method to find the root of equation

//program to implement bisection method to find the root of equation f(x)=x^3-4x-9=0
#include<stdio.h>
#include<conio.h>
#include<math.h>
double f(float x)
{
return(x*x*x-4*x-9);//Here you can change it
}
void main()
{
clrscr();
float a,b,c,e;
printf("\n Enter the values of a and b : ");
scanf("%f  %f",&a,&b);
printf("\n Enter the value of epsilon : ");
scanf("%f",&e);
if(f(a)*f(b)>0)
{
printf("\n initial approximation are not suitable!!!");
}
else
{
do
{
c=(a+b)/2;
if(f(a)*f(c)<0)
{
b=c;
}
else
{
a=c;
}
}
while(fabs((double) (a-b)) >e) ;
printf("\n\t Approximate value is = %f",c);
}
getch();
}

Comments

Popular Posts