← All examples

Quadratic equation

Pascal Branching

discriminant, if / else

Flowchart (ISO 5807)

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

Source code

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;