' Math functions
#COMPILE EXE
#DIM ALL

FUNCTION Factorial(BYVAL n AS LONG) AS LONG
    IF n <= 1 THEN FUNCTION = 1 ELSE FUNCTION = n * Factorial(n - 1)
END FUNCTION

FUNCTION GCD(BYVAL a AS LONG, BYVAL b AS LONG) AS LONG
    LOCAL t AS LONG
    WHILE b <> 0
        t = b
        b = a MOD b
        a = t
    WEND
    FUNCTION = a
END FUNCTION

FUNCTION PBMAIN() AS LONG
    PRINT "Factorial(5)=" + STR$(Factorial(5))
    PRINT "GCD(48,18)=" + STR$(GCD(48, 18))
    PRINT "Done."
    FUNCTION = 0
END FUNCTION
