Bisection Method in C

The bisection method in mathematics is a root-finding method that repeatedly bisects an interval and then selects a subinterval in which a root must lie for further processing. It is a very simple and robust method, but it is also relatively slow.

Equation: x2-10

Features of Bisection Method:

Program of Bisection in C

  #include<stdio.h>
  #include<conio.h>
  #include<math.h> 
  // #define f(x) x*x-10 float f(float x)
  
  float f(float x)
  {
     float z;
     z=x*x-10;
     return z;
  }
  
  void main()
  {
     int count=1,n;
     float a,b,m;
     clrscr(); 
     printf("ENTER THE INTERVALS A and B :- ");
     xyz: 
     scanf("%f%f",&a,&b); 
     printf("No.of Iteration.");
     scanf("%d",&n);
     if(f(a)*f(b)<0);
     {
      m=(a+b)/2;
      while(count<=n)
       {
       if(f(a)*f(m)<0)
         {
           b=m;
         }
      else
      {
          a=m;
      }
       count++;
       m=(a+b)/2;
     }
     printf("Answer is : %f",m);
    }
  
    getch();
   }
   

Output

bisection program

Post Your Comment