annotate lab3/gcdfun.p @ 0:bfdcc3820b32

Basis
author Mike Spivey <mike@cs.ox.ac.uk>
date Thu, 05 Oct 2017 08:04:15 +0100
parents
children
rev   line source
0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
1 (* lab3/gcdfun.p *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
3 proc gcd(x, y);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
4 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
5 while x <> y do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
6 if x > y then
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
7 x := x - y
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
8 else
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
9 y := y - x
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
10 end
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
11 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
12 return x
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
13 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
14
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
15 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
16 print gcd(3*37, 7*37); newline
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
17 end.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
18
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
19 (*<<
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
20 37
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
21 >>*)