← All examples

GCD (Euclid)

Pascal Algorithms

while + I/O

Flowchart (ISO 5807)

YesNoStartInput a bb <> 0t = bb = a mod ba = tOutput aEndFigure 1 — GCD

Source code

program GCD;
var a, b, t: integer;
begin
  readln(a, b);
  while b <> 0 do
  begin
    t := b;
    b := a mod b;
    a := t;
  end;
  writeln(a);
end.