Skip to content

Quadratic equation

Pascal discriminant, if / else

Flowchart (ISO 5807)

YesNoYesNoStartInput a, b, cd = b² − 4acd > 0x1 = (−b + √d) / (2a)x2 = (−b − √d) / (2a)Output «x1=», x1, «x2=», x2d = 0Output «x=» − b / (2a)Output «Дійсних коренів немає»EndFigure 1 — Solve

Source code

Pascal
procedure Solve(a, b, c: real);
var d, x1, x2: real;
begin
  d := b * b - 4 * a * c;
  if d > 0 then
  begin
    x1 := (-b + sqrt(d)) / (2 * a);
    x2 := (-b - sqrt(d)) / (2 * a);
    writeln('x1=', x1, ' x2=', x2);
  end
  else if d = 0 then
    writeln('x=', -b / (2 * a))
  else
    writeln('Дійсних коренів немає');
end;

The editor opens with this code — change it and the chart redraws.

Language
Pascal
Constructs
discriminant, if / else
Topic
Branching
Formats
Word, Visio, draw.io, PDF, SVG

Related examples