Quadratic equation solving algorithm

 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\]

or

\[x=\frac{-b}{2a}\ \ \qquad\ \qquad\ for\ \Delta=0\]

When 

\[\Delta<0\]
the equation has no solution.

\[\Delta=b^2-4ac\]

 

 alg square en

Implementation of the algorithm in language: Pascal, C++, Java, Python, JavaScript

Description of the algorithm:

  1. Start - This is where our algorithm begins.
  2. We read the input data - the coefficients a, b, and c of the equation.
  3. We check whether the coefficient a of the equation is equal to 0.
  4. If a=0, we have a linear equation; we call the linear equation solving algorithm.
  5. We calculate the value of delta (Δ).
  6. We check whether delta is less than 0.
  7. If Δ<0, we print the information that the equation has no solutions.
  8. We check whether delta is equal to 0.
  9. If Δ=0, we calculate the value of the one double solution, x.
  10. When Δ=0, after calculating x, we print its value.
  11. 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​.
  12. We print the calculated values of both solutions.
  13. Stop - The common end point of the algorithm for all paths.