Created
May 14, 2017 12:16
-
-
Save antranigv/e56261202b9da5007db2e5918953149b to your computer and use it in GitHub Desktop.
GCD in Oberon-2 for voc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MODULE gcd; | |
IMPORT Out, Modules; | |
VAR GCD: INTEGER; arg0, arg1: LONGINT; | |
PROCEDURE Gcd(a, b : INTEGER): INTEGER; | |
BEGIN | |
IF a = 0 THEN RETURN b END; | |
IF b = 0 THEN RETURN a END; | |
IF b > a THEN RETURN Gcd(b, a); | |
ELSE RETURN Gcd(b, a MOD b) END; | |
END Gcd; | |
BEGIN | |
Modules.GetIntArg(1, arg0); Modules.GetIntArg(2, arg1); | |
GCD := Gcd(SHORT(arg0), SHORT(arg1)); | |
Out.Int(arg0 DIV GCD, 0); Out.Int(arg1 DIV GCD, 10); | |
Out.Ln | |
END gcd. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment