aboutsummaryrefslogtreecommitdiff
path: root/examples/gcd.imp
blob: 5ab0bbf152072b9bdfb6b519b4858a68995d2e1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/* 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;

x := 48;
y := 18;
gcd(x, y; result);