C program to solve quadratic expression using bisection method root finding




C program to solve quadratic expression using bisection method (Algorithm)

#include<stdio.h>

int main(){

    float a,b,c,pgauss,ngauss;
    float x,fx;

    printf("Enter a, b, c negative gauss and positive gauss: ");
    scanf("%f%f%f%f%f",&a,&b,&c,&pgauss,&ngauss);

    x = ngauss;
     fx =( a * x * x ) + (b * x) + c;

    while(fx != 0.0) {
         x = (x + pgauss)/2;
         fx =( a * x * x ) + (b * x) + c;
    }

    printf("One solution of quadratic equation in given range: %f",x);
    return 0;
}

Sample output:

Enter a, b, c negative gauss and positive gauss: 1 0 -25 4 6
One solution of quadratic equation in given range: 5.000000

Enter a, b, c negative gauss and positive gauss: 1 0 -25 -2 -8
One solution of quadratic equation in given range: -5.000000



No comments: