The term b 2-4ac is known as the discriminant of a quadratic equation. The discriminant tells the nature of the roots. If discriminant is greater than 0, the roots are real and different. If discriminant is equal to 0, the roots are real and equal. If discriminant is less than 0, the roots are complex and different. Quadratic Equation Algorithm. 1 Step: Input the coefficients of the quadratic equation from the user and store in the variables a,b and c. 2 Step: Now find the Discriminant of the equation by using formula Discriminant= (b.b)- (4.a.c). 3 Step: Now compute their roots based on the nature of Discriminants.
- Quadratic Equation Program in C A quadratic equation is an equation of the second degree, meaning it contains at least one term that is squared. The standard form of the quadratic equation is ax² + bx + c = 0 where a, b, and c are real and a!=0, x is an unknown variable. The nature of roots is determined by the discriminant.
- C Program to Find All Roots of a Quadratic Equation. C Programming Server Side Programming. A quadratic equation is in the form ax 2 + bx + c. The roots of the quadratic equation are given by the following formula −. There are three cases −. B 2 c - The roots are not real i.e. They are complex. B 2 = 4.a.c - The roots are real.
- C Program to Find All Roots of a Quadratic Equation This program accepts coefficients of a quadratic equation from the user and displays the roots (both real and complex roots depending upon the discriminant). To understand this example, you should have the knowledge of the following C programming topics: C if, if.else and Nested if.else.
Here we will a write a program to solve quadratic equation in C++ programming language. Let’s first understand how to solve a quadratic equation:
Let’s take the quadratic equation as:ax²+bx+c=0
How program works:
- Take the values for a, b and c (double type).
- if, a = b = 0 then invalid equation
- if b² -4ac < 0 then the real roots
- if b² -4ac > 0 , x1= (-b+√(b² -4ac))/2a , x1= (-b -√(b² -4ac))/2a
- The C++ function for √x is sqrt(x).
- Include math.h for using the sqrt() function.
Now let’s write the program for the same.
C++ Program To Find Quadratic Equation
Here is a program to solve Quadratic equation in Python
C Program To Find Discriminant Of Quadratic Equation
Program to solve Quadratic equation in C++
OUTPUT:
Please comment for any concern or suggestions for improvements.