Implement Method of Bisection using C



Method of Bisection,Sumit Kar, Numerical Methods, C, Timus Rak


/* Method of Bisection



Equation: x^3-4x-9=0*/


#include<stdio.h>
#include<math.h>
void main()
{
float a,b,k,m;
float f(float);
printf("\nEnter first initial value:: ");
scanf("%f",&a);
printf("\nEnter second initial value:: ");
scanf("%f",&b);
while(fabs(a-b)>0.00001)
{
m=(a+b)/2;
k=f(m);
if(k>0)
b=m;
else
a=m;
}
printf("\nRoot is:: %f",m);
}
float f(float x)
{
return (x*x*x)-(4*x)-9;
}


0 Comments