A C program to find Roots of Quadratic equation

First, the program accepts 3 values and then uses the expression b2 – 4ac is called the discriminant. The value of the discriminant shows how many roots f(x) has: - If b2 – 4ac > 0 then the quadratic function has two distinct real roots. - If b2 – 4ac = 0 then the quadratic function has one repeated real root.

Then if the result, lets name it d. If d is less than 0 it uses the formula -b/(2*a). and if d is greater than 0 it uses the formula (-b +square root of d)/(2*a).

#include <math.h>
int main(){
  printf("Program to print the Quadratic Equation");
  float a,b,c,r1,r2,d;
  printf("Enter the value of a,b,c\n");
    printf("Roots are real and equal\n");
    printf("Root1=%f,Root 2=%f\n",r1,r2);
  else if(d>0)
    printf("Roots are real and defined");
    printf("Root 1=%f",r1);
    printf("Root 2=%f",r2);
    printf("Root ax are imaginary\n");

This is a simple program to find the roots of a quadratic equation. This program uses math.h to find the sq root.

And don't forget to follow and share this blog with a friend who wants to learn programming.

Thank you...