The general form of the quadratic equation can be written as follows:
\[ax^2 + bx + c = 0\]
where a, b, and c are known real numbers, called the coefficients of the equation. In order to calculate the roots of this equation, i.e., to find the solutions, we will use generally known formulas:
\[x_{1}=\frac{-b+\sqrt[]{\Delta }}{2a}, \ \
x_{2}=\frac{-b-\sqrt[]{\Delta }}{2a} \hspace{1.5cm} for \ \Delta >0\]
x_{2}=\frac{-b-\sqrt[]{\Delta }}{2a} \hspace{1.5cm} for \ \Delta >0\]
or
\[x=\frac{-b}{2a}\ \ \qquad\ \qquad\ for\ \Delta=0\]
When
\[\Delta<0\]
the equation has no solution.
\[\Delta=b^2-4ac\]
Implementation of the algorithm in language: Pascal, C++, Java, Python, JavaScript
Description of the algorithm:
- Start - This is where our algorithm begins.
- We read the input data - the coefficients a, b, and c of the equation.
- We check whether the coefficient a of the equation is equal to 0.
- If a=0, we have a linear equation; we call the linear equation solving algorithm.
- We calculate the value of delta (Δ).
- We check whether delta is less than 0.
- If Δ<0, we print the information that the equation has no solutions.
- We check whether delta is equal to 0.
- If Δ=0, we calculate the value of the one double solution, x.
- When Δ=0, after calculating x, we print its value.
- We reach this point when none of the previous conditions (Δ<0 and Δ=0) have been met, which means Δ>0. We calculate the values of the two solutions of the equation: x1 and x2.
- We print the calculated values of both solutions.
- Stop - The common end point of the algorithm for all paths.
