# C Program to find Root of a Function using Bisection method (Computational technique)

Updated on May 23, 2013

Bisection method is used for solving the non linear equations. It is the simplest and robust numerical method to find the roots of a equation. The main principle on which this method works is that it repeatedly bisects any selected interval at first iteration and then select a sub interval in which approximated root lies for further operation.

The interval (b,m) is so chosen such that f(b) is positive and f(m) is negative. Then these points are plotted on the x vs f(x) graph, a line is produced which must pass through a point, such that f(x)=0. We got to find this x only as the root.

## C Program Source Code For Bisection Method

`#include<stdio.h> `
`#include<math.h> `
`#define epsilon 1e-6 `
`void main() `
`{ `
`float b1,b2,b,m,m1,m2,dx; `
`int found,converged,j; `
`found=0; `
`printf("Enter your first guess or approximation\n"); `
`scanf("%f",&b1); `
`m1=b1*b1*b1-15; `
`printf("Your 1st value is %f\n",m1); `
`while (found==0) `
`{ `
`printf("Enter your second guess or approximation\n"); `
`scanf("%f",&b2); `
`m2=b2*b2*b2-15; `
`printf("Your 2nd value is %f\n",m2); `
`if(m1*m2>0) `
`{`
`found=0;`
`} `
`else `
`found=1; `
`} `
`printf("The right guess\n"); `
`j=1; `
`while(converged==0) `
`{ `
`printf("\n iteration no. =%d \n",j); `
`b=(b1+b2)/2; `
`printf("The new guess is %f \n",b); `
`m=b*b*b-15; `
`printf("The new value is %f \n",m); `
`if(m*m1>0) `
`{ `
`b1=b; `
`printf("The next guess is %f \n",b); `
`dx=(b1-b2)/b1; `
`} `
`else `
`{ `
`b2=b; `
`printf("The next guess is %f \n",b); `
`dx=(b1-b2)/b1; `
`} `
`if(fabs(dx)<epsilon) `
`{converged=1;} `
`j=j+1; `
`} `
`printf("\nth calculated value is %lf\n",m); `
`}`

163

0

9

0

0