Recent Post

3/recentposts

Sunday, January 21, 2018

BISECTION METHOD IN C PROGRAMMING

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
float function(float x)
{
    return (exp(x)+x);
}
void main()
{
    float a,b,c;
    printf("Enter a and b : ");
    scanf("%f%f",&a,&b);
    if(function(a)*function(b)>0)
    {
        printf("Enter appropriate interval\n");
        exit(0);
    }
    else
    {
        do
        {
            c=(a+b)/2;
            if(function(a)*function(c)<0)
            {
                b=c;
            }
            else
            {
                a=c;
            }
        }while(fabs(function(c))>0.0005);
            printf("solution = %f \t\tf(x)= %f",c,function(c));
    }

}

Share:

0 comments:

Post a Comment

Recent

Unordered List

Definition List

Pages

Theme Support