# Need help with bisection method

#### Haziqrazale

Write a program to find the roots of / − () using the bisection method. The program should ask the user for initial estimates of and . The program should then print out the value of the root, accurate to 10e-9 . Additionally, make the program print out how many iterations (bisections) it takes to achieve the required accuracy.

#### Haziqrazale

Write a program to find the roots of x/5 − cos(x) using the bisection method. The program should ask the user for initial estimates of and . The program should then print out the value of the root, accurate to 10e-9 . Additionally, make the program print out how many iterations (bisections) it takes to achieve the required accuracy.

#include <stdio.h>
#include <stdlib.h>
#include<math.h>
// Let the Function is : x^3-4x-4.224
double function(double x)
{
return (x/5 - cos(x));
}
int main()
{
double a,b,c;
double xmin=0,xmax=0;
printf("Enter a number for Xmin: ", xmin);
scanf("%lf", &xmin);

printf("\nEnter a number for Xmax: ", xmax);
scanf("%lf", &xmax);

while(function(xmin)function(xmax)>0)
{
xmin--;
xmax++;
}
if(function(xmax)function(xmax-1)<=0)
{
a=xmax-1;
b=xmax+1;
}
else
{
a=xmin-1;
b=xmin+1;
}
while(fabs(a-b)>=0.0001)
{
c=(a+b)/2;
printf("[%f %f %f]\n",a,b,c);
if(function(c)==0)
break;
else if(function(a)function(c)<0)
b=c;
else
a=c;
}
printf("The root is %.9f\n",c);
return 0;
}