The terminology is wrong. You are finding solutions to a quadratic equation, either using the quadratic formula or completing the square. You are not 'solving the quadratic formula by completing the square' (although the quadratic formula is derived by completing the square on the general equation). The solutions of the quadratic equation ax 2 + bx + c = 0 correspond to the roots of the function f(x) = ax 2 + bx + c, since they are the values of x for which f(x) = 0. As shown in Figure 2, if a, b, and c are real numbers and the domain of f is the set of real numbers, then the roots of f are exactly the x - coordinates of the points where. This online calculator is a quadratic equation solver that will solve a second-order polynomial equation such as ax 2 + bx + c = 0 for x, where a ≠ 0, using the quadratic formula. The calculator solution will show work using the quadratic formula to solve the entered equation for real and complex roots.
I have given here a C program to solve any Quadratic 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.
- When it is equal to zero, we will get one Real Solution.
- When it is less than Zero, we will get two Imaginary Solutions.
When there is an imaginary solutions, we have to use the factor i to represent imaginary part as it is a complex number.
// quadratic equation is a second order of polynomial equation in a single variable
// x = [ -b +/- sqrt(b^2 - 4ac) ] / 2a
void SolveQuadratic(double a, double b, double c)
double sqrtpart = b*b - 4*a*c;
double x, x1, x2, img;
if(sqrtpart > 0)
x1 = (-b + sqrt(sqrtpart)) / (2 * a);
x2 = (-b - sqrt(sqrtpart)) / (2 * a);
printf('Two Real Solutions: %.4lf or %.4lfnn', x1, x2);
elseif(sqrtpart < 0)
sqrtpart = -sqrtpart;
x = -b / (2 * a);
img = sqrt(sqrtpart) / (2 * a);
printf('Two Imaginary Solutions: %.4lf + %.4lf i or %.4lf + %.4lf inn', x, img, x, img);
x = (-b + sqrt(sqrtpart)) / (2 * a);
printf('One Real Solution: %.4lfnn', x);
// 6x^2 + 11x - 35 = 0
SolveQuadratic(6, 11, -35);
// 5x^2 + 6x + 1 = 0
SolveQuadratic(5, 6, 1);
// 2x^2 + 4x + 2 = 0
SolveQuadratic(2, 4, 2);
// 5x^2 + 2x + 1 = 0
SolveQuadratic(5, 2, 1);
Two Real Solutions: 1.6667 or -3.5000
Two Real Solutions: -0.2000 or -1.0000
One Real Solution: -1.0000
Two Imaginary Solutions: -0.2000 + 0.4000 i or -0.2000 + 0.4000 i
Press any key to continue . . .
The C++ program to solve quadratic equations in standard form is a simple program based on the quadratic formula. Given the coefficients as input, it will solve the equation and output the roots of the equation.
Dev C++ Online
This is a simple program is intended for intermediate level C++ programmers.
The program is compiled using Dev-C++ 126.96.36.199 version installed on a Windows 7 64-bit PC. You may try other standard C compilers and the program will still work if you use the correct C libraries.
In this program, we solve the quadratic equation using the formula
Where a, b and c are coefficient of the equation which is in the standard form.
How to compute?
The steps to compute the quadratic equation is given below.
The program request the input coefficient values a, b and c. When the user input the values, it will compute two terms t1 and t3 and an intermediate term t2.
term2 () is called in step 2 and returned value of function is assigned to
term2 () function receives the coefficient values – a, b, c and compute the value for
term () function returns and assign value of
b2 – 4ac to
t2 and it is useful in understanding the root of the quadratic equation.
If (t2 < 0), then the roots are not real
Dev C++ For Windows 10
If (t2 0) then, there is exactly one root value.
If (t2 > 0) then there are two root values.
The above condition is checked and printed with output values. Now we need to compute the roots and display the output values.
t3 is assigned value after taking square root of
Finally, we have t1 and t3 to compute two roots of a quadratic equation.
root are calculated and printed immediately.
Flowchart – Program for Quadratic Equations
To understand flow of logic of this program, see the flowchart below.
Program Code – Program for Quadratic Equation
Dev C++ Download Windows 10
The output of the above program is given below.