aboutsummaryrefslogtreecommitdiff
path: root/examples/gcd.imp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/gcd.imp')
-rw-r--r--examples/gcd.imp16
1 files changed, 16 insertions, 0 deletions
diff --git a/examples/gcd.imp b/examples/gcd.imp
new file mode 100644
index 0000000..5ab0bbf
--- /dev/null
+++ b/examples/gcd.imp
@@ -0,0 +1,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);