Code for Bisection method in C

C code to implement Bisection method .  Compiled in DEV C++

website_caption1

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
float f(float x)
{
float sum;
sum=pow(x,3)+x+3;
return sum;
}
main()
{
float a,b,c,y0,y1,m;
step:
printf("enter the value of a,b and c ");
scanf("%f%f%f",&a,&b,&c);
y1=f(a);
y0=f(b);
if(y0*y1>0)
           {
           goto step;
           }
step1:
m=(a+b)/2;
if(f(m)==0)
{
printf("the root is : %f",m);
exit(0);
}
else
     {
     if (y1*f(m)<0)
        b=m;
     else
        a=m;
     }
 if(a-b>c)
          {
                   goto step1;
                   }
                   printf("the root is :%f",m);
                   getch();
                   }

website_caption1
 You might be also interested in :

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s