Second order Quadratic Equation

C Program to Solve Second Order Quadratic Equation (ax2 + bx + c).

Program

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
	float a, b, c;
  	float disc, root1, root2;

  	printf("\nEnter the Values of a : ");
  	scanf("%f", &a);
  	printf("\nEnter the Values of b : ");
  	scanf("%f", &b);
  	printf("\nEnter the Values of c : ");
  	scanf("%f", &c);

  	disc = (b * b) - (4 * a * c);

  	root1 = (-b + sqrt(disc)) / (2.0 * a);
  	root2 = (-b - sqrt(disc)) / (2.0 * a);

  	printf("\nFirst root : %f", root1);
  	printf("\nSecond root : %f", root2);

	getch();
}

Output

Enter the Values of a : 2

Enter the Values of b : -8

Enter the Values of c : -24

First root : 6.000000
Second root : -2.000000

Explanation

The standard form of a quadratic equation is:
ax2 + bx + c = 0, where
a, b and c are real numbers and
a != 0


The term "b2-4ac" is known as the discriminant of a quadratic equation.
Roots of the quadratic equation are





In the above program, values of a, b and c are taken from the user and roots are calculated using the above formula.

The roots of the equation can depend on the value of determinant, the detailed solution can be seen here.