I want to calculate the root of a quadratic equation ax2 + bx + c = 0. I think my algorithm is correct, but I am new to functions and I think my mistake is with calling them. Could you help me? Thank you in advance. Here is the code. Oct 01, 2009 If the polynomial is divided by one of its roots, we will get zero as the remainder in the last step. Then, the polynomial will be reduced to a quadratic equation of the form Ax2+Bx+C=0 where A is a, B is bnew and C is cnew. Then the quadratic equation is solved. Now, we have all 3 roots of the equation. Quadratic equation is a second order of polynomial equation in a single variable. X = -b +/- sqrt(b^2 - 4ac) / 2a We have to find the value of (b.b - 4.a.c). When it is greater than Zero, we will get two Real Solutions.
- Related Questions & Answers
- Selected Reading
C++ProgrammingServer Side Programming
A quadratic equation is in the form ax2 + bx + c. The roots of the quadratic equation are given by the following formula −
There are three cases −
b2 < 4*a*c - The roots are not real i.e. they are complex
b2 = 4*a*c - The roots are real and both roots are the same.
b2 > 4*a*c - The roots are real and both roots are different
The program to find the roots of a quadratic equation is given as follows.
Example
Output
In the above program, first the discriminant is calculated. If it is greater than 0, then both the roots are real and different.
This is demonstrated by the following code snippet.
If the discriminant is equal to 0, then both the roots are real and same. This is demonstrated by the following code snippet.
Quadratic Equation Examples
If the discriminant is less than 0, then both the roots are complex and different. This is demonstrated by the following code snippet.