aboutsummaryrefslogtreecommitdiff
path: root/examples/gcd.imp
blob: 530f3478f4b163cbb6da21e510fbfe7a417dbf16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* computes greatest common divisor (gcd) of a and b */
procedure gcd(a, b; r) begin
  if b = 0 then
    r := a;
  else
    q := a;
    while q >= b do
      q := q - b;
    end;
    gcd(b, q; r);
  end;
end;

gcd(48, 18; result);