$ ! Multiplication Table $ ! $ ! (C) 2005-2006 Dr. ERDI Gergo $ ! $ ! See http://cactus.rulez.org/elte/2005-1-vms/#1 for a description of what it does $ ! $ ! Licensed under the GNU General Public License, version 2 $ $ !---------- $ ! #1: Check arguments $ $ ERROR = "WRITE SYS$ERROR ""ERROR: "", " $ $ IF (P1 .EQS. "") $ THEN $ ERROR "nincs parameter" $ EXIT $ ENDIF $ $ IF (F$TYPE(P1) .NES. "INTEGER") $ THEN $ ERROR """", P1, """ is not a number $ EXIT $ ENDIF $ $ IF (F$TYPE(P2) .NES. "INTEGER") THEN P2 = 1 $ $ !---------- $ ! #2: Main program $ $ ! Calculate column width $ $ IF (P2 .EQ. 1) $ THEN $ max = P1 * P1 $ ELSE $ max = P2 - 1 $ ENDIF $ CALL decimals 'max' $ w = r $ $ ! Print lines $ i = 1 $ LOOP_B: $ IF (i .GT. P1) THEN GOTO LOOP_E $ CALL mpline 'i' 'P1' 'w' 'P2' $ i = i + 1 $ GOTO LOOP_B $ LOOP_E: $ EXIT $ $ !---------- $ ! #3: Definition of subroutines $ $ ! decimals x: Calculates the number of decimal digits in 'x', $ ! and stores the result in the global 'r' $ decimals: SUBROUTINE $ r == 1 $ LOOP_B: $ IF (P1 .LT. 10) THEN GOTO LOOP_E $ P1 = P1 / 10 $ r == r + 1 $ GOTO LOOP_B $ LOOP_E: $ ENDSUBROUTINE $ $ $ ! mpline x n w m: Print x*1 x*2 ... x*n in columns of width w, $ ! modulo m $ mpline: SUBROUTINE $ x = P1 $ n = P2 $ w = P3 $ m = P4 $ $ i = 1 $ sor = "" $ LOOP_B: $ IF (i .GT. P2) THEN GOTO LOOP_E $ y = x * i $ CALL mod 'y' 'm' $ CALL pad 'F$STR(r)' 'w' $ sor = sor + r $ IF (i .NE. P2) THEN sor = sor + " " $ i = i + 1 $ GOTO LOOP_B $ LOOP_E: $ SAY sor $ ENDSUBROUTINE $ $ $ ! pad s w: Pads the string 's' to width 'w', by adding $ ! space characters to its left. The result is $ ! stored in the global variable 'r' $ pad: SUBROUTINE $ s = P1 $ w = P2 $ $ r == s $ i = F$LEN(s) $ LOOP_B: $ IF (i .GE. w) THEN GOTO LOOP_E $ r == " " + r $ i = i + 1 $ GOTO LOOP_B $ LOOP_E: $ ENDSUBROUTINE $ $ ! mod n m: Stores n mod m in the global variable 'r' $ mod: SUBROUTINE $ r == P1 $ IF (P2 .NE. 1) THEN r == P1 - ((P1/P2) * P2) $ ENDSUBROUTINE