Multiplication tables: Difference between revisions

m
m (→‎{{header|Wren}}: Minor tidy)
 
(34 intermediate revisions by 16 users not shown)
Line 12:
{{trans|C}}
 
<langsyntaxhighlight lang="11l">V n = 12
L(j) 1..n
print(‘#3’.format(j), end' ‘ ’)
Line 23:
L(j) 1..n
print(I j < i {‘ ’} E ‘#3 ’.format(i * j), end' ‘’)
print(‘│ ’i)</langsyntaxhighlight>
 
{{out}}
Line 44:
 
=={{header|360 Assembly}}==
<langsyntaxhighlight lang="360asm">* 12*12 multiplication table 14/08/2015
MULTTABL CSECT
USING MULTTABL,R12
Line 103:
PORT DC C'--+-------------------------------------------------'
YREGS
END MULTTABL</langsyntaxhighlight>
{{out}}
<pre> | 1 2 3 4 5 6 7 8 9 10 11 12
Line 122:
=={{header|8080 Assembly}}==
 
<langsyntaxhighlight lang="8080asm"> org 100h
lxi h,output
;;; Make the header
Line 218:
inx h
ret
output: equ $</langsyntaxhighlight>
 
{{out}}
Line 240:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
<lang AArch64 Assembly>
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program multtable64.s */
Line 391:
.include "../includeARM64.inc"
 
</syntaxhighlight>
</lang>
{{Output}}
<pre>
Line 410:
 
=={{header|Action!}}==
<langsyntaxhighlight Actionlang="action!">PROC PrintRight(BYTE num,size)
BYTE i
 
Line 470:
OD
OD
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Multiplication_tables.png Screenshot from Atari 8-bit computer]
Line 491:
 
=={{header|ActionScript}}==
<syntaxhighlight lang="actionscript">
<lang ActionScript>
package {
Line 571:
 
}
</syntaxhighlight>
</lang>
 
=={{header|Ada}}==
<syntaxhighlight lang="ada">
<lang Ada>
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
Line 600:
end loop;
end Multiplication_Table;
</syntaxhighlight>
</lang>
<pre>
| 1 2 3 4 5 6 7 8 9 10 11 12
Line 620:
=={{header|Agena}}==
{{Trans|ALGOL_W}}
<langsyntaxhighlight lang="agena">scope
# print a school style multiplication table
# NB: print outputs a newline at the end, write and printf do not
Line 633:
od;
print()
epocs</langsyntaxhighlight>
{{out}}
<pre>
Line 658:
 
<!-- {{does not work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release 1.8.8d.fc9.i386 - missing printf and FORMAT}} -->
<langsyntaxhighlight Algol68lang="algol68">main:(
INT max = 12;
INT width = ENTIER(log(max)*2)+1;
Line 676:
OD;
printf(($gl$, hr))
)</langsyntaxhighlight>
{{out}}
<pre>
Line 698:
 
=={{header|ALGOL W}}==
<langsyntaxhighlight lang="algolw">begin
% print a school style multiplication table %
i_w := 3; s_w := 0; % set output formating %
Line 711:
end;
 
end.</langsyntaxhighlight>
{{out}}
<pre>
Line 729:
12| 144
</pre>
 
=={{header|APL}}==
A simple table is trivial:
<syntaxhighlight lang="apl">(⍳12)∘.×⍳12</syntaxhighlight>
 
But that prints out all the duplicated results across the diagonal:
 
{{Out}}
<pre> 1 2 3 4 5 6 7 8 9 10 11 12
2 4 6 8 10 12 14 16 18 20 22 24
3 6 9 12 15 18 21 24 27 30 33 36
4 8 12 16 20 24 28 32 36 40 44 48
5 10 15 20 25 30 35 40 45 50 55 60
6 12 18 24 30 36 42 48 54 60 66 72
7 14 21 28 35 42 49 56 63 70 77 84
8 16 24 32 40 48 56 64 72 80 88 96
9 18 27 36 45 54 63 72 81 90 99 108
10 20 30 40 50 60 70 80 90 100 110 120
11 22 33 44 55 66 77 88 99 110 121 132
12 24 36 48 60 72 84 96 108 120 132 144</pre>
 
Getting just the top half, and some labels, requires a bit more work. Text alignment varies with implementation so the numbers will need some tweaking:
 
{{works with|Dyalog APL}}
<syntaxhighlight lang="apl">⎕←(' ×',2↑' '),4 0⍕⍳12⋄{⎕←((4 0⍕⍵),⊂1(4×(⍵-1))⍴' '),4 0⍕(⍵-1)↓(⍵×⍳12)}¨⍳12</syntaxhighlight>
 
{{works with|GNU APL}}
After printing the table, GNU APL will will output the value of the expression that produced it, so in addition to adjusting the header spacing this solution uses <tt>⍬⊣</tt> to throw that value away.
 
<syntaxhighlight lang="apl">⎕←(' ×',4↑' '),4 0⍕⍳12⋄⍬⊣{⎕←((4 0⍕⍵),⊂1(4×(⍵-1))⍴' '),4 0⍕(⍵-1)↓(⍵×⍳12)}¨⍳12</syntaxhighlight>
 
{{Out}}
<pre> × 1 2 3 4 5 6 7 8 9 10 11 12
1 1 2 3 4 5 6 7 8 9 10 11 12
2 4 6 8 10 12 14 16 18 20 22 24
3 9 12 15 18 21 24 27 30 33 36
4 16 20 24 28 32 36 40 44 48
5 25 30 35 40 45 50 55 60
6 36 42 48 54 60 66 72
7 49 56 63 70 77 84
8 64 72 80 88 96
9 81 90 99 108
10 100 110 120
11 121 132
12 144</pre>
 
=={{header|AppleScript}}==
===Iteration===
<langsyntaxhighlight AppleScriptlang="applescript ">set n to 12 -- Size of table.
repeat with x from 0 to n
if x = 0 then set {table, x} to {{return}, -1}
Line 752 ⟶ 797:
set text item delimiters to ""
return (characters -4 thru -1 of (" " & x)) as string
end f</langsyntaxhighlight>
{{out}}
<pre>"
Line 774 ⟶ 819:
 
{{trans|JavaScript}} (ES5 functional version)
<langsyntaxhighlight AppleScriptlang="applescript">------------------- MULTIPLICATION TABLE -----------------
 
-- multiplicationTable :: Int -> Int -> String
Line 956 ⟶ 1,001:
end repeat
return out & dbl
end replicate</langsyntaxhighlight>
{{Out}}
<pre> x 1 2 3 4 5 6 7 8 9 10 11 12
Line 989 ⟶ 1,034:
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
<lang ARM Assembly>
 
/* ARM assembly Raspberry PI */
Line 1,172 ⟶ 1,217:
 
 
</syntaxhighlight>
</lang>
 
=={{header|Arturo}}==
<langsyntaxhighlight lang="rebol">mulTable: function [n][
print [" |"] ++ map 1..n => [pad to :string & 3]
print "----+" ++ join map 1..n => "----"
Line 1,186 ⟶ 1,231:
]
 
mulTable 12</langsyntaxhighlight>
 
{{out}}
Line 1,204 ⟶ 1,249:
11 | 121 132
12 | 144</pre>
 
=={{header|ASIC}}==
{{trans|Modula-2}}
<lang basic>
REM Multiplication tables
N = 12
PREDN = N - 1
WDTH = 3
CLS
FOR J = 1 TO PREDN
INTVAL = J
GOSUB PRINTINT:
PRINT " ";
NEXT J
INTVAL = N
GOSUB PRINTINT:
PRINT
FOR J = 0 TO PREDN
PRINT "----";
NEXT J
PRINT "+"
FOR I = 1 TO N
WDTH = 3
FOR J = 1 TO N
IF J < I THEN
PRINT " ";
ELSE
INTVAL = I * J
GOSUB PRINTINT:
PRINT " ";
ENDIF
NEXT J
PRINT "| ";
INTVAL = I
WDTH = 2
GOSUB PRINTINT:
PRINT
NEXT I
END
 
PRINTINT:
REM Writes the value of INTVAL in a field of the given WDTH
S2$ = STR$(INTVAL)
S2$ = LTRIM$(S2$)
SPNUM = LEN(S2$)
SPNUM = WDTH - SPNUM
S1$ = SPACE$(SPNUM)
PRINT S1$;
PRINT S2$;
RETURN
</lang>
{{out}}
<pre>
1 2 3 4 5 6 7 8 9 10 11 12
------------------------------------------------+
1 2 3 4 5 6 7 8 9 10 11 12 | 1
4 6 8 10 12 14 16 18 20 22 24 | 2
9 12 15 18 21 24 27 30 33 36 | 3
16 20 24 28 32 36 40 44 48 | 4
25 30 35 40 45 50 55 60 | 5
36 42 48 54 60 66 72 | 6
49 56 63 70 77 84 | 7
64 72 80 88 96 | 8
81 90 99 108 | 9
100 110 120 | 10
121 132 | 11
144 | 12
</pre>
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight lang="autohotkey">Gui, -MinimizeBox
Gui, Margin, 0, 0
Gui, Font, s9, Fixedsys
Line 1,309 ⟶ 1,286:
}
GuiControl,, Edit2, %Table%
Return</langsyntaxhighlight>
Message box shows:
<pre> x | 1 2 3 4 5 6 7 8 9 10 11 12
Line 1,328 ⟶ 1,305:
 
=={{header|AutoIt}}==
<langsyntaxhighlight AutoItlang="autoit">#AutoIt Version: 3.2.10.0
$tableupto=12
$table=""
Line 1,347 ⟶ 1,324:
Next
Next
msgbox(0,"Multiplication Tables",$table)</langsyntaxhighlight>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
BEGIN {
for(i=1;i<=12;i++){
Line 1,359 ⟶ 1,336:
print
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,378 ⟶ 1,355:
=={{header|Axe}}==
Since the standard text output is poorly suited to this kind of formatted data, this example is implemented by writing to the screen buffer using the small font. Also, the limits were adjusted to 10x8 to make the table fit the screen.
<langsyntaxhighlight lang="axe">Fix 5
ClrDraw
For(I,1,10)
Line 1,395 ⟶ 1,372:
DispGraph
getKeyʳ
Fix 4</langsyntaxhighlight>
 
Approximate output:
Line 1,412 ⟶ 1,389:
 
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
{{works with|QBasic}}
<syntaxhighlight lang="applesoftbasic">100 M = 12
110 DEF FN T(X) = X * 3 + (X < 4) * (4 - X) + (X > 10) * (X - 10) - 1
120 FOR N = -1 TO M
130 IF NOT N THEN PRINT CHR$(13) TAB(5); : FOR J = 5 TO FN T(M + 1) - 2 : PRINT "-"; : NEXT J, N
140 I = ABS(N)
150 IF N > 0 THEN PRINT CHR$(13) MID$(" ", 1, I < 10) I" !";
160 FOR J = I TO M
170 V$ = STR$(I * J)
180 PRINT TAB(FN T(J)) MID$(" ", 1, 3 - LEN(V$) - (J < 4)) V$;
190 NEXT J, N</syntaxhighlight>
 
==={{header|ASIC}}===
{{trans|Modula-2}}
<syntaxhighlight lang="basic">
REM Multiplication tables
N = 12
PREDN = N - 1
WDTH = 3
CLS
FOR J = 1 TO PREDN
INTVAL = J
GOSUB PRINTINT:
PRINT " ";
NEXT J
INTVAL = N
GOSUB PRINTINT:
PRINT
FOR J = 0 TO PREDN
PRINT "----";
NEXT J
PRINT "+"
FOR I = 1 TO N
WDTH = 3
FOR J = 1 TO N
IF J < I THEN
PRINT " ";
ELSE
INTVAL = I * J
GOSUB PRINTINT:
PRINT " ";
ENDIF
NEXT J
PRINT "| ";
INTVAL = I
WDTH = 2
GOSUB PRINTINT:
PRINT
NEXT I
END
 
PRINTINT:
REM Writes the value of INTVAL in a field of the given WDTH
S2$ = STR$(INTVAL)
S2$ = LTRIM$(S2$)
SPNUM = LEN(S2$)
SPNUM = WDTH - SPNUM
S1$ = SPACE$(SPNUM)
PRINT S1$;
PRINT S2$;
RETURN
</syntaxhighlight>
{{out}}
<pre>
1 2 3 4 5 6 7 8 9 10 11 12
------------------------------------------------+
1 2 3 4 5 6 7 8 9 10 11 12 | 1
4 6 8 10 12 14 16 18 20 22 24 | 2
9 12 15 18 21 24 27 30 33 36 | 3
16 20 24 28 32 36 40 44 48 | 4
25 30 35 40 45 50 55 60 | 5
36 42 48 54 60 66 72 | 6
49 56 63 70 77 84 | 7
64 72 80 88 96 | 8
81 90 99 108 | 9
100 110 120 | 10
121 132 | 11
144 | 12
</pre>
 
==={{header|BASIC256}}===
<syntaxhighlight lang="freebasic">print " X| 1 2 3 4 5 6 7 8 9 10 11 12"
print "---+------------------------------------------------"
 
for i = 1 to 12
nums$ = right(" " + string(i), 3) + "|"
for j = 1 to 12
if i <= j then
if j >= 1 then
nums$ += left(" ", (4 - length(string(i * j))))
end if
nums$ += string(i * j)
else
nums$ += " "
end if
next j
print nums$
next i</syntaxhighlight>
 
==={{header|BBC BASIC}}===
BBC BASIC automatically right-justifies numeric output.
<syntaxhighlight lang="bbcbasic"> @% = 5 : REM Set column width
FOR row% = 1 TO 12
PRINT row% TAB(row% * @%) ;
FOR col% = row% TO 12
PRINT row% * col% ;
NEXT col%
PRINT
NEXT row%</syntaxhighlight>
{{out}}
<pre> 1 1 2 3 4 5 6 7 8 9 10 11 12
2 4 6 8 10 12 14 16 18 20 22 24
3 9 12 15 18 21 24 27 30 33 36
4 16 20 24 28 32 36 40 44 48
5 25 30 35 40 45 50 55 60
6 36 42 48 54 60 66 72
7 49 56 63 70 77 84
8 64 72 80 88 96
9 81 90 99 108
10 100 110 120
11 121 132
12 144</pre>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
{{trans|IS-BASIC}}
<syntaxhighlight lang="qbasic">100 cls
110 print tab (4);
120 for i = 1 to 12
130 print using " ###";i;
140 next
150 print
160 print " --+------------------------------------------------"
170 for i = 1 to 12
180 print using " ##|";i;
190 print tab (i*4);
200 for j = i to 12
210 print using " ###";i*j;
220 next
230 print
240 next
250 end</syntaxhighlight>
 
==={{header|Commodore BASIC}}===
The table consumes every one of the 1000 cells in a 40-column display, and even so has to cheat a little to fit 10x10=100 into the table. It uses the INSERT character (<tt>CHR$(148)</tt>) to push characters over to the right after printing them without triggering a scroll that would push the top line off the screen.
<syntaxhighlight lang="gwbasic">100 PRINT CHR$(14);CHR$(147);
110 PRINT " X";
120 W=2
130 FOR I=1 TO 10
140 : N=I
150 : GOSUB 520
160 : PRINT ":"N$;
170 NEXT I
180 W=3
190 FOR I=11 TO 12
200 : N=I
210 : GOSUB 520
220 : PRINT ":"N$;
230 NEXT
240 FOR I=1 TO 12
250 : PRINT "--";
260 : FOR J=1 TO 10
270 : PRINT "+--";
280 : NEXT J
290 : FOR J=11 TO 12
300 : PRINT "+---";
310 : NEXT J
320 : N=I:W=2:GOSUB 520:PRINT N$;
330 : FOR J=1 TO 10
340 : W=2
350 : IF J<I THEN N$=" ":GOSUB 530:GOTO 370
360 : N=I*J:GOSUB 520
370 : IF LEN(N$)<3 THEN PRINT ":";
380 : PRINT N$;
390 : NEXT J
400 : FOR J=11 TO 12
410 : W=3
420 : IF J<I THEN N$=" ":GOSUB 530:GOTO 440
430 : N=I*J:GOSUB 520
440 : PRINT N$;
450 : FOR K=1 TO LEN(N$): PRINT CHR$(157);:NEXT K
460 : PRINT CHR$(148);":";
470 : IF J<12 THEN FOR K=1 TO LEN(N$):PRINT CHR$(29);: NEXT K
480 : NEXT J: IF I<12 THEN PRINT
490 NEXT I
500 GET K$: IF K$="" THEN 500
510 END
520 N$=MID$(STR$(N),2)
530 IF LEN(N$)<W THEN N$=" "+N$:GOTO 530
540 RETURN</syntaxhighlight>
 
{{Out}}
<pre> x: 1: 2: 3: 4: 5: 6: 7: 8: 9:10: 11: 12
--+--+--+--+--+--+--+--+--+--+--+---+---
1: 1: 2: 3: 4: 5: 6: 7: 8: 9:10: 11: 12
--+--+--+--+--+--+--+--+--+--+--+---+---
2: : 4: 6: 8:10:12:14:16:18:20: 22: 24
--+--+--+--+--+--+--+--+--+--+--+---+---
3: : : 9:12:15:18:21:24:27:30: 33: 36
--+--+--+--+--+--+--+--+--+--+--+---+---
4: : : :16:20:24:28:32:36:40: 44: 48
--+--+--+--+--+--+--+--+--+--+--+---+---
5: : : : :25:30:35:40:45:50: 55: 60
--+--+--+--+--+--+--+--+--+--+--+---+---
6: : : : : :36:42:48:54:60: 66: 72
--+--+--+--+--+--+--+--+--+--+--+---+---
7: : : : : : :49:56:63:70: 77: 84
--+--+--+--+--+--+--+--+--+--+--+---+---
8: : : : : : : :64:72:80: 88: 96
--+--+--+--+--+--+--+--+--+--+--+---+---
9: : : : : : : : :81:90: 99:108
--+--+--+--+--+--+--+--+--+--+--+---+---
10: : : : : : : : : 100:110:120
--+--+--+--+--+--+--+--+--+--+--+---+---
11: : : : : : : : : : :121:132
--+--+--+--+--+--+--+--+--+--+--+---+---
12: : : : : : : : : : : :144</pre>
==={{header|FreeBASIC}}===
<syntaxhighlight lang="freebasic">
' FB 1.05.0 Win64
 
Print " X|";
For i As Integer = 1 To 12
Print Using "####"; i;
Next
 
Print
Print "---+"; String(48, "-")
 
For i As Integer = 1 To 12
Print Using "###"; i;
Print"|"; Spc(4 * (i - 1));
For j As Integer = i To 12
Print Using "####"; i * j;
Next j
Print
Next i
 
Print
Print "Press any key to quit"
Sleep</syntaxhighlight>
 
{{out}}
<pre>
X| 1 2 3 4 5 6 7 8 9 10 11 12
---+------------------------------------------------
1| 1 2 3 4 5 6 7 8 9 10 11 12
2| 4 6 8 10 12 14 16 18 20 22 24
3| 9 12 15 18 21 24 27 30 33 36
4| 16 20 24 28 32 36 40 44 48
5| 25 30 35 40 45 50 55 60
6| 36 42 48 54 60 66 72
7| 49 56 63 70 77 84
8| 64 72 80 88 96
9| 81 90 99 108
10| 100 110 120
11| 121 132
12| 144
</pre>
 
==={{header|FutureBasic}}===
<syntaxhighlight lang="basic">
long i, j
 
window 1, @"Multiplication Table", (0,0,420,220)
 
print " |";
for i = 1 to 12
print using "####"; i;
next
print :print "---+"; string$(48, "-")
for i = 1 to 12
print using "###"; i;
print"|"; spc(4 * (i - 1));
for j = i to 12
print using "####"; i * j;
next
print
next
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
| 1 2 3 4 5 6 7 8 9 10 11 12
---+------------------------------------------------
1| 1 2 3 4 5 6 7 8 9 10 11 12
2| 4 6 8 10 12 14 16 18 20 22 24
3| 9 12 15 18 21 24 27 30 33 36
4| 16 20 24 28 32 36 40 44 48
5| 25 30 35 40 45 50 55 60
6| 36 42 48 54 60 66 72
7| 49 56 63 70 77 84
8| 64 72 80 88 96
9| 81 90 99 108
10| 100 110 120
11| 121 132
12| 144
</pre>
 
==={{header|Gambas}}===
'''[https://gambas-playground.proko.eu/?gist=3a3a987766a9a9a383b3e0e8a65d9ea2 Click this link to run this code]'''
<syntaxhighlight lang="gambas">'Code 'stolen' from Free Basic and altered to work in Gambas
 
Public Sub Main()
Dim i, j As Integer
 
Print " X|";
For i = 1 To 12
Print Format(i, "####");
Next
Print
Print "---+"; String(48, "-")
For i = 1 To 12
Print Format(i, "###");
Print "|"; Space(4 * (i - 1));
For j = i To 12
Print Format(i * j, "####");
Next
Print
Next
 
End</syntaxhighlight>
Output:
<pre>
X| 1 2 3 4 5 6 7 8 9 10 11 12
---+------------------------------------------------
1| 1 2 3 4 5 6 7 8 9 10 11 12
2| 4 6 8 10 12 14 16 18 20 22 24
3| 9 12 15 18 21 24 27 30 33 36
4| 16 20 24 28 32 36 40 44 48
5| 25 30 35 40 45 50 55 60
6| 36 42 48 54 60 66 72
7| 49 56 63 70 77 84
8| 64 72 80 88 96
9| 81 90 99 108
10| 100 110 120
11| 121 132
12| 144
</pre>
 
==={{header|GW-BASIC}}===
{{trans|Modula-2}}
{{works with|BASICA}}
{{works with|PC-BASIC|any}}
<syntaxhighlight lang="gwbasic">
10 ' Multiplication Tables
20 LET N% = 12
30 FOR J% = 1 TO N% - 1
40 PRINT USING "###"; J%;
50 PRINT " ";
60 NEXT J%
70 PRINT USING "###"; N%
80 FOR J% = 0 TO N% - 1
90 PRINT "----";
100 NEXT J%
110 PRINT "+"
120 FOR I% = 1 TO N%
130 FOR J% = 1 TO N%
140 IF J% < I% THEN PRINT " "; ELSE PRINT USING "###"; I% * J%;: PRINT " ";
150 NEXT J%
160 PRINT "| "; USING "##"; I%
170 NEXT I%
</syntaxhighlight>
{{out}}
<pre>
1 2 3 4 5 6 7 8 9 10 11 12
------------------------------------------------+
1 2 3 4 5 6 7 8 9 10 11 12 | 1
4 6 8 10 12 14 16 18 20 22 24 | 2
9 12 15 18 21 24 27 30 33 36 | 3
16 20 24 28 32 36 40 44 48 | 4
25 30 35 40 45 50 55 60 | 5
36 42 48 54 60 66 72 | 6
49 56 63 70 77 84 | 7
64 72 80 88 96 | 8
81 90 99 108 | 9
100 110 120 | 10
121 132 | 11
144 | 12
</pre>
 
==={{header|IS-BASIC}}===
<syntaxhighlight lang="is-basic">100 PROGRAM "Multipli.bas"
110 TEXT 80
120 PRINT TAB(7);
130 FOR I=1 TO 12
140 PRINT USING " ###":I;
150 NEXT
160 PRINT AT 2,5:"----------------------------------------------------"
170 FOR I=1 TO 12
180 PRINT USING "### |":I;:PRINT TAB(I*4+3);
190 FOR J=I TO 12
200 PRINT USING " ###":I*J;
210 NEXT
220 PRINT
230 NEXT</syntaxhighlight>
 
==={{header|Liberty BASIC}}===
<syntaxhighlight lang="lb">Print " | 1 2 3 4 5 6 7 8 9 10 11 12"
Print "--+------------------------------------------------------------"
 
For i = 1 To 12
nums$ = Right$(" " + str$(i), 2) + "|"
For ii = 1 To 12
If i <= ii Then
If ii >= 1 Then
nums$ = nums$ + Left$(" ", (5 - Len(str$(i * ii))))
End If
nums$ = nums$ + str$(i * ii)
Else
nums$ = nums$ + " "
End If
Next ii
Print nums$
Next i</syntaxhighlight>
{{out}}
<pre>
| 1 2 3 4 5 6 7 8 9 10 11 12
--+------------------------------------------------------------
1| 1 2 3 4 5 6 7 8 9 10 11 12
2| 4 6 8 10 12 14 16 18 20 22 24
3| 9 12 15 18 21 24 27 30 33 36
4| 16 20 24 28 32 36 40 44 48
5| 25 30 35 40 45 50 55 60
6| 36 42 48 54 60 66 72
7| 49 56 63 70 77 84
8| 64 72 80 88 96
9| 81 90 99 108
10| 100 110 120
11| 121 132
12| 144
</pre>
 
==={{header|Microsoft Small Basic}}===
{{trans|Modula-2}}
<syntaxhighlight lang="microsoftsmallbasic">
n = 12
For j = 1 To n - 1
TextWindow.CursorLeft = (j - 1) * 4 + (3 - Text.GetLength(j))
TextWindow.Write(j)
TextWindow.Write(" ")
EndFor
TextWindow.CursorLeft = (n - 1) * 4 + (3 - Text.GetLength(n))
TextWindow.Write(n)
TextWindow.WriteLine("")
For j = 0 To n - 1
TextWindow.Write("----")
EndFor
TextWindow.WriteLine("+")
For i = 1 To n
For j = 1 To n
If j < i Then
TextWindow.Write(" ")
Else
TextWindow.CursorLeft = (j - 1) * 4 + (3 - Text.GetLength(i * j))
TextWindow.Write(i * j)
TextWindow.Write(" ")
EndIf
EndFor
TextWindow.Write("| ")
TextWindow.CursorLeft = n * 4 + (4 - Text.GetLength(i))
TextWindow.Write(i)
TextWindow.WriteLine("")
EndFor
</syntaxhighlight>
{{out}}
<pre>
1 2 3 4 5 6 7 8 9 10 11 12
------------------------------------------------+
1 2 3 4 5 6 7 8 9 10 11 12 | 1
4 6 8 10 12 14 16 18 20 22 24 | 2
9 12 15 18 21 24 27 30 33 36 | 3
16 20 24 28 32 36 40 44 48 | 4
25 30 35 40 45 50 55 60 | 5
36 42 48 54 60 66 72 | 6
49 56 63 70 77 84 | 7
64 72 80 88 96 | 8
81 90 99 108 | 9
100 110 120 | 10
121 132 | 11
144 | 12
</pre>
 
==={{header|PureBasic}}===
<syntaxhighlight lang="purebasic">Procedure PrintMultiplicationTable(maxx, maxy)
sp = Len(Str(maxx*maxy)) + 1
trenner$ = "+"
For l1 = 1 To maxx + 1
For l2 = 1 To sp
trenner$ + "-"
Next
trenner$ + "+"
Next
header$ = "|" + RSet("x", sp) + "|"
For a = 1 To maxx
header$ + RSet(Str(a), sp)
header$ + "|"
Next
PrintN(trenner$)
PrintN(header$)
PrintN(trenner$)
For y = 1 To maxy
line$ = "|" + RSet(Str(y), sp) + "|"
For x = 1 To maxx
If x >= y
line$ + RSet(Str(x*y), sp)
Else
line$ + Space(sp)
EndIf
line$ + "|"
Next
PrintN(line$)
Next
PrintN(trenner$)
EndProcedure
 
OpenConsole()
PrintMultiplicationTable(12, 12)
Input()</syntaxhighlight>
 
Ouput similar to ALGOL 68
 
==={{header|QBasic}}===
<lang qbasic>CLS
<syntaxhighlight lang="qbasic">CLS
 
'header row
Line 1,439 ⟶ 1,940:
PRINT o$;
NEXT
NEXT</langsyntaxhighlight>
 
{{out}}
Line 1,459 ⟶ 1,960:
</pre>
 
==={{header|Run BASIC}}===
'''See also:''' [[#BBC BASIC|BBC BASIC]], [[#Liberty BASIC|Liberty BASIC]], [[#PureBasic|PureBasic]]
<syntaxhighlight lang="runbasic">html "<TABLE border=1 ><TR bgcolor=silver align=center><TD><TD>1<TD>2<TD>3<TD>4<TD>5<TD>6<TD>7<TD>8<TD>9<TD>10<TD>11<TD>12</td></TR>"
For i = 1 To 12
html "<TR align=right><TD>";i;"</td>"
For ii = 1 To 12
html "<td width=25>"
If ii >= i Then html i * ii
html "</td>"
Next ii
next i
html "</table>"
</syntaxhighlight>Output:
<TABLE border=1 ><TR bgcolor=silver align=center><TD><TD>1<TD>2<TD>3<TD>4<TD>5<TD>6<TD>7<TD>8<TD>9<TD>10<TD>11<TD>12</td></TR><TR align=right><TD>1</td><td width=25>1</td><td width=25>2</td><td width=25>3</td><td width=25>4</td><td width=25>5</td><td width=25>6</td><td width=25>7</td><td width=25>8</td><td width=25>9</td><td width=25>10</td><td width=25>11</td><td width=25>12</td><TR align=right><TD>2</td><td width=25></td><td width=25>4</td><td width=25>6</td><td width=25>8</td><td width=25>10</td><td width=25>12</td><td width=25>14</td><td width=25>16</td><td width=25>18</td><td width=25>20</td><td width=25>22</td><td width=25>24</td><TR align=right><TD>3</td><td width=25></td><td width=25></td><td width=25>9</td><td width=25>12</td><td width=25>15</td><td width=25>18</td><td width=25>21</td><td width=25>24</td><td width=25>27</td><td width=25>30</td><td width=25>33</td><td width=25>36</td><TR align=right><TD>4</td><td width=25></td><td width=25></td><td width=25></td><td width=25>16</td><td width=25>20</td><td width=25>24</td><td width=25>28</td><td width=25>32</td><td width=25>36</td><td width=25>40</td><td width=25>44</td><td width=25>48</td><TR align=right><TD>5</td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25>25</td><td width=25>30</td><td width=25>35</td><td width=25>40</td><td width=25>45</td><td width=25>50</td><td width=25>55</td><td width=25>60</td><TR align=right><TD>6</td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25>36</td><td width=25>42</td><td width=25>48</td><td width=25>54</td><td width=25>60</td><td width=25>66</td><td width=25>72</td><TR align=right><TD>7</td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25>49</td><td width=25>56</td><td width=25>63</td><td width=25>70</td><td width=25>77</td><td width=25>84</td><TR align=right><TD>8</td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25>64</td><td width=25>72</td><td width=25>80</td><td width=25>88</td><td width=25>96</td><TR align=right><TD>9</td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25>81</td><td width=25>90</td><td width=25>99</td><td width=25>108</td><TR align=right><TD>10</td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25>100</td><td width=25>110</td><td width=25>120</td><TR align=right><TD>11</td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25>121</td><td width=25>132</td><TR align=right><TD>12</td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25>144</td></table>
 
=== {{header|ApplesoftTiny BASIC}} ===
{{trans|Modula-2}}
<lang ApplesoftBasic>100 M = 12
{{works with|TinyBasic}}
110 DEF FN T(X) = X * 3 + (X < 4) * (4 - X) + (X > 10) * (X - 10) - 1
<syntaxhighlight lang="basic">
120 FOR N = -1 TO M
10 REM MULTIPLICATION TABLES
130 IF NOT N THEN PRINT CHR$(13) TAB(5); : FOR J = 5 TO FN T(M + 1) - 2 : PRINT "-"; : NEXT J, N
20 LET N=12
140 I = ABS(N)
30 REM TO ALIGN NUMBERS TO THE RIGHT
150 IF N > 0 THEN PRINT CHR$(13) MID$(" ", 1, I < 10) I" !";
40 REM ASSUME THAT N IS AT MOST TWO-DIGIT.
160 FOR J = I TO M
50 LET J=1
170 V$ = STR$(I * J)
60 PRINT " ";
180 PRINT TAB(FN T(J)) MID$(" ", 1, 3 - LEN(V$) - (J < 4)) V$;
70 IF J<10 THEN PRINT " ";
190 NEXT J, N</lang>
80 PRINT J;" ";
90 LET J=J+1
100 IF J=N THEN GOTO 120
110 GOTO 60
120 PRINT " ";
130 IF N<10 THEN PRINT " ";
140 PRINT N
150 LET J=0
160 PRINT "----";
170 J=J+1
180 IF J=N THEN GOTO 200
190 GOTO 160
200 PRINT "+"
210 LET I=1
220 LET J=1
230 IF J<I THEN GOTO 290
240 LET P=I*J
250 IF P<100 THEN PRINT " ";
260 IF P<10 THEN PRINT " ";
270 PRINT P;" ";
280 GOTO 300
290 PRINT " ";
300 IF J=N THEN GOTO 330
310 LET J=J+1
320 GOTO 230
330 PRINT "! ";
340 IF I<10 THEN PRINT " ";
350 PRINT I
360 IF I=N THEN GOTO 390
370 LET I=I+1
380 GOTO 220
390 END
</syntaxhighlight>
{{out}}
<pre>
1 2 3 4 5 6 7 8 9 10 11 12
------------------------------------------------+
1 2 3 4 5 6 7 8 9 10 11 12 ! 1
4 6 8 10 12 14 16 18 20 22 24 ! 2
9 12 15 18 21 24 27 30 33 36 ! 3
16 20 24 28 32 36 40 44 48 ! 4
25 30 35 40 45 50 55 60 ! 5
36 42 48 54 60 66 72 ! 6
49 56 63 70 77 84 ! 7
64 72 80 88 96 ! 8
81 90 99 108 ! 9
100 110 120 ! 10
121 132 ! 11
144 ! 12
</pre>
 
==={{header|IS-True BASIC}}===
<syntaxhighlight lang="qbasic">PRINT " X| 1 2 3 4 5 6 7 8 9 10 11 12"
<lang IS-BASIC>100 PROGRAM "Multipli.bas"
PRINT "---+------------------------------------------------"
110 TEXT 80
 
120 PRINT TAB(7);
130 FOR Ii = 1 TO 12
LET nums$ = (" " & STR$(i))[LEN(" " & STR$(i))-3+1:maxnum] & "|"
140 PRINT USING " ###":I;
FOR j = 1 TO 12
150 NEXT
IF i <= j THEN
160 PRINT AT 2,5:"----------------------------------------------------"
IF j >= 1 THEN LET nums$ = nums$ & (" ")[1:(4-LEN(STR$(i*j)))]
170 FOR I=1 TO 12
LET nums$ = nums$ & STR$(i*j)
180 PRINT USING "### |":I;:PRINT TAB(I*4+3);
190 FOR J=I TO 12 ELSE
LET nums$ = nums$ & " "
200 PRINT USING " ###":I*J;
END IF
210 NEXT
220 PRINT NEXT j
PRINT nums$
230 NEXT</lang>
NEXT i
PRINT
END</syntaxhighlight>
 
==={{header|uBasic/4tH}}===
{{trans|BBC BASIC}}
<syntaxhighlight lang="basic">For R = 1 To 12
Print R;Tab(R * 5);
For C = R To 12
Print Using "_____";R * C;
Next
Print
Next</syntaxhighlight>
{{out}}
<pre>1 1 2 3 4 5 6 7 8 9 10 11 12
2 4 6 8 10 12 14 16 18 20 22 24
3 9 12 15 18 21 24 27 30 33 36
4 16 20 24 28 32 36 40 44 48
5 25 30 35 40 45 50 55 60
6 36 42 48 54 60 66 72
7 49 56 63 70 77 84
8 64 72 80 88 96
9 81 90 99 108
10 100 110 120
11 121 132
12 144
 
0 OK, 0:105</pre>
 
==={{header|VBA}}===
<syntaxhighlight lang="vb">
Option Explicit
 
Sub Multiplication_Tables()
Dim strTemp As String, strBuff As String
Dim i&, j&, NbDigits As Byte
 
'You can adapt the following const :
Const NB_END As Byte = 12
 
Select Case NB_END
Case Is < 10: NbDigits = 3
Case 10 To 31: NbDigits = 4
Case 31 To 100: NbDigits = 5
Case Else: MsgBox "Number too large": Exit Sub
End Select
strBuff = String(NbDigits, " ")
For i = 1 To NB_END
strTemp = Right(strBuff & i, NbDigits)
For j = 2 To NB_END
If j < i Then
strTemp = strTemp & strBuff
Else
strTemp = strTemp & Right(strBuff & j * i, NbDigits)
End If
Next j
Debug.Print strTemp
Next i
End Sub
</syntaxhighlight>
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 10 11 12
2 4 6 8 10 12 14 16 18 20 22 24
3 9 12 15 18 21 24 27 30 33 36
4 16 20 24 28 32 36 40 44 48
5 25 30 35 40 45 50 55 60
6 36 42 48 54 60 66 72
7 49 56 63 70 77 84
8 64 72 80 88 96
9 81 90 99 108
10 100 110 120
11 121 132
12 144</pre>
 
==={{header|Visual Basic}}===
{{works with|Visual Basic|VB6 Standard}}
<syntaxhighlight lang="vb">Sub Main()
Const nmax = 12, xx = 3
Const x = xx + 1
Dim i As Integer, j As Integer, s As String
s = String(xx, " ") & " |"
For j = 1 To nmax
s = s & Right(String(x, " ") & j, x)
Next j
Debug.Print s
s = String(xx, "-") & " +"
For j = 1 To nmax
s = s & " " & String(xx, "-")
Next j
Debug.Print s
For i = 1 To nmax
s = Right(String(xx, " ") & i, xx) & " |"
For j = 1 To nmax
If j >= i _
Then s = s & Right(String(x, " ") & i * j, x) _
Else s = s & String(x, " ")
Next j
Debug.Print s
Next i
End Sub 'Main</syntaxhighlight>
{{Out}}
<pre>
| 1 2 3 4 5 6 7 8 9 10 11 12
--- + --- --- --- --- --- --- --- --- --- --- --- ---
1 | 1 2 3 4 5 6 7 8 9 10 11 12
2 | 4 6 8 10 12 14 16 18 20 22 24
3 | 9 12 15 18 21 24 27 30 33 36
4 | 16 20 24 28 32 36 40 44 48
5 | 25 30 35 40 45 50 55 60
6 | 36 42 48 54 60 66 72
7 | 49 56 63 70 77 84
8 | 64 72 80 88 96
9 | 81 90 99 108
10 | 100 110 120
11 | 121 132
12 | 144
</pre>
 
==={{header|XBasic}}===
{{trans|Modula-2}}
{{works with|Windows XBasic}}
<syntaxhighlight lang="xbasic">
PROGRAM "multiplicationtables"
VERSION "0.0001"
 
DECLARE FUNCTION Entry()
 
FUNCTION Entry()
$N = 12
FOR j@@ = 1 TO $N - 1
PRINT FORMAT$("### ", j@@);
NEXT j@@
PRINT FORMAT$("###", $N)
FOR j@@ = 0 TO $N - 1
PRINT "----";
NEXT j@@
PRINT "+"
FOR i@@ = 1 TO $N
FOR j@@ = 1 TO $N
IF j@@ < i@@ THEN
PRINT " ";
ELSE
PRINT FORMAT$("### ", i@@ * j@@);
END IF
NEXT j@@
PRINT "|"; FORMAT$(" ##", i@@)
NEXT i@@
END FUNCTION
END PROGRAM
</syntaxhighlight>
{{out}}
<pre>
1 2 3 4 5 6 7 8 9 10 11 12
------------------------------------------------+
1 2 3 4 5 6 7 8 9 10 11 12 | 1
4 6 8 10 12 14 16 18 20 22 24 | 2
9 12 15 18 21 24 27 30 33 36 | 3
16 20 24 28 32 36 40 44 48 | 4
25 30 35 40 45 50 55 60 | 5
36 42 48 54 60 66 72 | 6
49 56 63 70 77 84 | 7
64 72 80 88 96 | 8
81 90 99 108 | 9
100 110 120 | 10
121 132 | 11
144 | 12
</pre>
 
==={{header|BASIC256Yabasic}}===
<langsyntaxhighlight lang="freebasic">print " X| 1 2 3 4 5 6 7 8 9 10 11 12"
print "---+------------------------------------------------"
 
for i = 1 to 12
nums$ = right$(" " + stringstr$(i), 3) + "|"
for j = 1 to 12
if i <= j then
if j >= 1 then
nums$ += nums$ + left$(" ", (4 - lengthlen(stringstr$(i * j))))
end if
nums$ += stringnums$ + str$(i * j)
else
nums$ += nums$ + " "
end if
next j
print nums$
next i</langsyntaxhighlight>
 
=={{header|Batch File}}==
<langsyntaxhighlight lang="dos">@echo off
setlocal enabledelayedexpansion
 
Line 1,555 ⟶ 2,286:
for /l %%A in (1,1,%numspaces%) do set "space=!space! "
goto :EOF
::/The Functions.</langsyntaxhighlight>
{{Out}}
<pre>
Line 1,574 ⟶ 2,305:
 
Press any key to continue . . .</pre>
 
=={{header|BBC BASIC}}==
BBC BASIC automatically right-justifies numeric output.
<lang bbcbasic> @% = 5 : REM Set column width
FOR row% = 1 TO 12
PRINT row% TAB(row% * @%) ;
FOR col% = row% TO 12
PRINT row% * col% ;
NEXT col%
PRINT
NEXT row%</lang>
{{out}}
<pre> 1 1 2 3 4 5 6 7 8 9 10 11 12
2 4 6 8 10 12 14 16 18 20 22 24
3 9 12 15 18 21 24 27 30 33 36
4 16 20 24 28 32 36 40 44 48
5 25 30 35 40 45 50 55 60
6 36 42 48 54 60 66 72
7 49 56 63 70 77 84
8 64 72 80 88 96
9 81 90 99 108
10 100 110 120
11 121 132
12 144</pre>
 
=={{header|Befunge}}==
<langsyntaxhighlight lang="befunge">0>51p0>52p51g52g*:51g52g`!*\!51g52g+*+0\3>01p::55+%68*+\!28v
w^p2<y|!`+66:+1,+*84*"\"!:g25$_,#!>#:<$$_^#!:-1g10/+55\-**<<
"$9"^x>$55+,51g1+:66+`#@_055+68*\>\#<1#*-#9:#5_$"+---">:#,_$</langsyntaxhighlight>
 
{{out}}
Line 1,624 ⟶ 2,331:
<code>Table</code> formats a multiplication table for any given n. The result is a character array and can be printed with <code>•Out˘</code>. The overall structure is to build a 3-by-3 array of parts, then put them together with a two-dimensional join (<code>∾</code>).
 
<langsyntaxhighlight lang="bqn">Table ← {
m ← •Repr¨ ×⌜˜1+↕𝕩 # The numbers, formatted individually
main ← ⟨ # Bottom part: three sections
Line 1,635 ⟶ 2,342:
}
•Out˘ Table 12</langsyntaxhighlight>
{{Out}}
<langpre> | 1 2 3 4 5 6 7 8 9 10 11 12
--+-----------------------------------------------
1| 1 2 3 4 5 6 7 8 9 10 11 12
Line 1,650 ⟶ 2,357:
10| 100 110 120
11| 121 132
12| 144</langpre>
 
=={{header|Bracmat}}==
<langsyntaxhighlight Bracmatlang="bracmat"> ( multiplicationTable
= high i j row row2 matrix padFnc tmp
, celPad leftCelPad padFnc celDashes leftDashes
Line 1,708 ⟶ 2,415:
)
& out$(multiplicationTable$12)
& done;</langsyntaxhighlight>
{{out}}
<pre> X| 1 2 3 4 5 6 7 8 9 10 11 12
Line 1,726 ⟶ 2,433:
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <stdio.h>
 
int main(void)
Line 1,742 ⟶ 2,449:
return 0;
}</langsyntaxhighlight>
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 10 11 12
Line 1,760 ⟶ 2,467:
 
=={{header|C sharp}}==
<langsyntaxhighlight lang="csharp">using System;
 
namespace multtbl
Line 1,798 ⟶ 2,505:
}
}
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,822 ⟶ 2,529:
and formats the table columns.
 
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <iomanip>
#include <cmath> // for log10()
Line 1,899 ⟶ 2,606:
return 0;
}
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,933 ⟶ 2,640:
=={{header|Chef}}==
 
<langsyntaxhighlight lang="chef">Multigrain Bread.
 
Prints out a multiplication table.
Line 1,997 ⟶ 2,704:
Pour contents of the 2nd mixing bowl into the 2nd baking dish.
 
Serves 2.</langsyntaxhighlight>
 
{{out}}
Line 2,018 ⟶ 2,725:
This is more generalized.
Any size can be used and the table will be formatted appropriately.
<langsyntaxhighlight lang="lisp">(let [size 12
trange (range 1 (inc size))
fmt-width (+ (.length (str (* size size))) 1)
Line 2,031 ⟶ 2,738:
(for [j trange] j))))))]
(println s)))
</syntaxhighlight>
</lang>
 
{{out}}
Line 2,050 ⟶ 2,757:
 
=={{header|COBOL}}==
<langsyntaxhighlight COBOLlang="cobol"> identification division.
program-id. multiplication-table.
 
Line 2,096 ⟶ 2,803:
goback.
end program multiplication-table.
</syntaxhighlight>
</lang>
{{out}}
<pre>prompt$ cobc -xj multiplication-table.cob
Line 2,114 ⟶ 2,821:
 
=={{header|CoffeeScript}}==
<langsyntaxhighlight lang="coffeescript">
print_multiplication_tables = (n) ->
width = 4
Line 2,146 ⟶ 2,853:
print_multiplication_tables 12
</syntaxhighlight>
</lang>
 
{{out}}
Line 2,168 ⟶ 2,875:
 
=={{header|Common Lisp}}==
<langsyntaxhighlight lang="lisp">
(do ((m 0 (if (= 12 m) 0 (1+ m)))
(n 0 (if (= 12 m) (1+ n) n)))
Line 2,185 ⟶ 2,892:
(format t "~4,D" (* m n))
(format t " "))))))
</syntaxhighlight>
</lang>
Output:
<pre>
Line 2,207 ⟶ 2,914:
=={{header|D}}==
{{trans|PicoLisp}}
<langsyntaxhighlight lang="d">void main() {
import std.stdio, std.array, std.range, std.algorithm;
 
Line 2,215 ⟶ 2,922:
writefln("%4d" ~ " ".replicate(4 * (y - 1)) ~ "%(%4d%)", y,
iota(y, n + 1).map!(x => x * y));
}</langsyntaxhighlight>
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 10 11 12
Line 2,233 ⟶ 2,940:
 
=={{header|DCL}}==
<langsyntaxhighlight DCLlang="dcl">$ max = 12
$ h = f$fao( "!4* " )
$ r = 0
Line 2,258 ⟶ 2,965:
$ write sys$output f$fao( "!4SL", r ) + o
$ r = r + 1
$ if r .le. max then $ goto loop1</langsyntaxhighlight>
{{out}}
<pre>$ @multiplication_tables
Line 2,280 ⟶ 2,987:
=={{header|Delphi}}==
{{trans|DWScript}}
<langsyntaxhighlight lang="delphi">program MultiplicationTables;
 
{$APPTYPE CONSOLE}
Line 2,309 ⟶ 3,016:
Writeln;
end;
end.</langsyntaxhighlight>
 
=={{header|Draco}}==
<langsyntaxhighlight lang="draco">/* Print N-by-N multiplication table */
proc nonrec multab(byte n) void:
byte i,j;
Line 2,337 ⟶ 3,044:
 
/* Print 12-by-12 multiplication table */
proc nonrec main() void: multab(12) corp</langsyntaxhighlight>
{{out}}
<pre> | 1 2 3 4 5 6 7 8 9 10 11 12
Line 2,356 ⟶ 3,063:
=={{header|DWScript}}==
 
<langsyntaxhighlight lang="delphi">const size = 12;
var row, col : Integer;
 
Line 2,374 ⟶ 3,081:
PrintLn('');
end;
</syntaxhighlight>
</lang>
 
=={{header|E}}==
 
<langsyntaxhighlight lang="e"> def size := 12
println(`{|style="border-collapse: collapse; text-align: right;"`)
println(`|`)
Line 2,391 ⟶ 3,098:
}
}
println("|}")</langsyntaxhighlight>
 
Targets MediaWiki markup.
Line 2,583 ⟶ 3,290:
=={{header|EasyLang}}==
 
<syntaxhighlight lang="easylang">
<lang>n = 12
n = 12
func out h . .
numfmt 0 4
if h < 10
write " "
elif h < 100
write " "
.
write " "
write h
.
write " "
for i = 1 to n
call outwrite i
.
print ""
write " "
for i = 1 to n
write "----"
.
print ""
for i = 1 to n
call outwrite i
write "|"
for j = 1 to n
if j < i
write " "
else
call out write i * j
.
.
print ""
.
.</lang>
</syntaxhighlight>
 
=={{header|EchoLisp}}==
<langsyntaxhighlight lang="scheme">
(lib 'matrix)
 
Line 2,630 ⟶ 3,331:
(array-print (build-array 13 13 mtable))
 
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,649 ⟶ 3,350:
 
=={{header|Elixir}}==
<langsyntaxhighlight lang="elixir">defmodule RC do
def multiplication_tables(n) do
IO.write " X |"
Line 2,664 ⟶ 3,365:
end
 
RC.multiplication_tables(12)</langsyntaxhighlight>
 
{{out}}
Line 2,682 ⟶ 3,383:
11 | 121 132
12 | 144
</pre>
 
=={{header|EMal}}==
{{trans|TypeScript}}
<syntaxhighlight lang="emal">
int NUMBER = 12
for int j = 1; j <= NUMBER; ++j do write((text!j).padStart(3, " ") + " ") end
writeLine()
writeLine("----" * NUMBER + "+")
for int i = 1; i <= NUMBER; i++
for int j = 1; j <= NUMBER; ++j
write(when(j < i, " ", (text!(i * j)).padStart(3, " ") + " "))
end
writeLine("| " + (text!i).padStart(2, " "))
end
</syntaxhighlight>
{{out}}
<pre>
1 2 3 4 5 6 7 8 9 10 11 12
------------------------------------------------+
1 2 3 4 5 6 7 8 9 10 11 12 | 1
4 6 8 10 12 14 16 18 20 22 24 | 2
9 12 15 18 21 24 27 30 33 36 | 3
16 20 24 28 32 36 40 44 48 | 4
25 30 35 40 45 50 55 60 | 5
36 42 48 54 60 66 72 | 6
49 56 63 70 77 84 | 7
64 72 80 88 96 | 8
81 90 99 108 | 9
100 110 120 | 10
121 132 | 11
144 | 12
</pre>
 
=={{header|Erlang}}==
<syntaxhighlight lang="erlang">
<lang Erlang>
-module( multiplication_tables ).
 
Line 2,710 ⟶ 3,443:
[io:fwrite("~5B", [Sum]) || {_Y, Sum} <- Uptos],
io:nl().
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,731 ⟶ 3,464:
 
=={{header|Euphoria}}==
<langsyntaxhighlight Euphorialang="euphoria">puts(1," x")
for i = 1 to 12 do
printf(1," %3d",i)
Line 2,748 ⟶ 3,481:
end for
puts(1,'\n')
end for</langsyntaxhighlight>
 
{{out}}
Line 2,775 ⟶ 3,508:
 
{{Works with|Office 365 betas 2021}}
<langsyntaxhighlight lang="lisp">FNOVERHALFCARTESIANPRODUCT
=LAMBDA(f,
LAMBDA(n,
Line 2,791 ⟶ 3,524:
)
)
)</langsyntaxhighlight>
 
and also assuming the following generic bindings in the Name Manager for the WorkBook:
 
<langsyntaxhighlight lang="lisp">MUL
=LAMBDA(a, LAMBDA(b, a * b))
 
Line 2,804 ⟶ 3,537:
POWER(n, e)
)
)</langsyntaxhighlight>
 
(The single formula in cell '''B2''' below populates the whole 12*12 grid)
Line 3,221 ⟶ 3,954:
=={{header|F Sharp|F#}}==
Translation of C#
<syntaxhighlight lang="fsharp">
<lang FSharp>
open System
 
Line 3,241 ⟶ 3,974:
 
multTable ()
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,261 ⟶ 3,994:
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: io kernel math math.parser math.ranges sequences ;
IN: multiplication-table
 
Line 3,277 ⟶ 4,010:
" +" write
12 [ "----" write ] times nl
1 12 [a,b] [ print-row ] each ;</langsyntaxhighlight>
 
<pre>
Line 3,297 ⟶ 4,030:
 
=={{header|FALSE}}==
<langsyntaxhighlight lang="false">[$100\>[" "]?$10\>[" "]?." "]p:
[$p;! m: 2[$m;\>][" "1+]# [$13\>][$m;*p;!1+]#%"
"]l:
1[$13\>][$l;!1+]#%</langsyntaxhighlight>
 
=={{header|Fantom}}==
 
<langsyntaxhighlight lang="fantom">
class Main
{
Line 3,326 ⟶ 4,059:
}
}
</syntaxhighlight>
</lang>
 
=={{header|Forth}}==
<langsyntaxhighlight lang="forth">
: multiplication-table
cr 2 spaces 13 2 do i 4 u.r loop
Line 3,339 ⟶ 4,072:
loop
loop ;
</syntaxhighlight>
</lang>
 
=={{header|Fortran}}==
{{works with|Fortran|90 and later}}
<langsyntaxhighlight lang="fortran">program multtable
implicit none
 
Line 3,361 ⟶ 4,094:
end do
 
end program multtable</langsyntaxhighlight>
 
===Traditional approach===
Line 3,367 ⟶ 4,100:
 
So instead, write the table by first writing a line to a CHARACTER variable then blanking out the unwanted part.
<syntaxhighlight lang="fortran">
<lang Fortran>
Cast forth a twelve times table, suitable for chanting at school.
INTEGER I,J !Steppers.
Line 3,379 ⟶ 4,112:
3 WRITE (6,"(A)") ALINE !Print the text.
END !"One one is one! One two is two! One three is three!...
</syntaxhighlight>
</lang>
Output in the same style as above, with underlining unavailable: those who have used a lineprinter's overprint facility to properly underline find the flabby modern requirement of a second line vexing, but, few output devices support underlining in so easy a way.
×| 1 2 3 4 5 6 7 8 9 10 11 12
Line 3,396 ⟶ 4,129:
12| 144
Going to the trouble of preparing results, and then blanking some might seem a little too crude. An alternative would be to use a different FORMAT statement for each line of output. But, a collection of a dozen output statements hardly represents a programming solution. Instead, create and then use the text of FORMAT statements, as follows. Notice that there are ''no reserved words'' in Fortran.
<syntaxhighlight lang="fortran">
<lang Fortran>
Cast forth a twelve times table, suitable for chanting at school.
INTEGER I,J !Steppers.
Line 3,407 ⟶ 4,140:
3 WRITE (6,FORMAT) I,(I*J, J = I,12) !Use it.
END !"One one is one! One two is two! One three is three!...
</syntaxhighlight>
</lang>
The output is the same, so instead, here are the generated FORMAT texts:
(I3,'|',0X,12I4)
Line 3,428 ⟶ 4,161:
 
===VAX FORTRAN===
<syntaxhighlight lang="fortran">
<lang Fortran>
PROGRAM TABLES
IMPLICIT NONE
Line 3,453 ⟶ 4,186:
C
END
</langsyntaxhighlight>Based on the above code but with a slight modification as VAX FORTRAN doesn't allow zero width fields in a format statement. The number of rows and columns can also be altered by modifying the value of K which must be in the range 1 - 25.
===FORTRAN-IV===
<langsyntaxhighlight Fortranlang="fortran"> PROGRAM TABLES
C
C Produce a formatted multiplication table of the kind memorised by rote
Line 3,489 ⟶ 4,222:
3 CONTINUE
C
END</langsyntaxhighlight>Rather more changes are needed to produce the same result, in particular we cannot modify the format specifier directly and have to rely on overlaying it with an integer array and calculating the ASCII values needed for each byte we need to modify. Nested implicit DO loops are allowed, but not used as it isn't possible to compute K on the fly so we have to calculate (and store) the results for each row before printing it. Note also that the unit numbers for the output devices are different and when using Hollerith strings to define values in a DATA statement the size of each string must match the size of the data type.
 
===Microsoft FORTRAN-80===
The use of a non standard(?) BYTE data type available in Microsoft FORTRAN-80 makes it easier to understand what is going on.
<langsyntaxhighlight Fortranlang="fortran"> PROGRAM TABLES
C
C Produce a formatted multiplication table of the kind memorised by rote
Line 3,525 ⟶ 4,258:
3 CONTINUE
C
END</langsyntaxhighlight>Inserting the following two lines before the inner DO loop will print the format specifier used to print each row of the table.<langsyntaxhighlight Fortranlang="fortran"> WRITE(1,4) (A(J), J = 1,24)
4 FORMAT(1x,24A1)</langsyntaxhighlight>Running the program produces the following output<langpre>
| 1 2 3 4 5 6 7 8 9 10 11 12
--+------------------------------------------------
Line 3,540 ⟶ 4,273:
10| 100 110 120
11| 121 132
12| 144</langpre>
 
=={{header|FreeBASIC}}==
<lang freebasic>
' FB 1.05.0 Win64
 
Print " X|";
For i As Integer = 1 To 12
Print Using "####"; i;
Next
 
Print
Print "---+"; String(48, "-")
 
For i As Integer = 1 To 12
Print Using "###"; i;
Print"|"; Spc(4 * (i - 1));
For j As Integer = i To 12
Print Using "####"; i * j;
Next j
Print
Next i
 
Print
Print "Press any key to quit"
Sleep</lang>
 
{{out}}
<pre>
X| 1 2 3 4 5 6 7 8 9 10 11 12
---+------------------------------------------------
1| 1 2 3 4 5 6 7 8 9 10 11 12
2| 4 6 8 10 12 14 16 18 20 22 24
3| 9 12 15 18 21 24 27 30 33 36
4| 16 20 24 28 32 36 40 44 48
5| 25 30 35 40 45 50 55 60
6| 36 42 48 54 60 66 72
7| 49 56 63 70 77 84
8| 64 72 80 88 96
9| 81 90 99 108
10| 100 110 120
11| 121 132
12| 144
</pre>
 
=={{header|Frink}}==
<langsyntaxhighlight lang="frink">a = makeArray[[13,13], {|a,b| a==0 ? b : (b==0 ? a : (a<=b ? a*b : ""))}]
formatTable[a,"right"]</langsyntaxhighlight>
 
{{out}}
Line 3,604 ⟶ 4,294:
11 121 132
12 144
</pre>
 
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=3a3a987766a9a9a383b3e0e8a65d9ea2 Click this link to run this code]'''
<lang gambas>'Code 'stolen' from Free Basic and altered to work in Gambas
 
Public Sub Main()
Dim i, j As Integer
 
Print " X|";
For i = 1 To 12
Print Format(i, "####");
Next
Print
Print "---+"; String(48, "-")
For i = 1 To 12
Print Format(i, "###");
Print "|"; Space(4 * (i - 1));
For j = i To 12
Print Format(i * j, "####");
Next
Print
Next
 
End</lang>
Output:
<pre>
X| 1 2 3 4 5 6 7 8 9 10 11 12
---+------------------------------------------------
1| 1 2 3 4 5 6 7 8 9 10 11 12
2| 4 6 8 10 12 14 16 18 20 22 24
3| 9 12 15 18 21 24 27 30 33 36
4| 16 20 24 28 32 36 40 44 48
5| 25 30 35 40 45 50 55 60
6| 36 42 48 54 60 66 72
7| 49 56 63 70 77 84
8| 64 72 80 88 96
9| 81 90 99 108
10| 100 110 120
11| 121 132
12| 144
</pre>
 
=={{header|Go}}==
<syntaxhighlight lang="go">
<lang go>
package main
 
Line 3,678 ⟶ 4,325:
fmt.Println("")
}
</syntaxhighlight>
</lang>
 
=={{header|Groovy}}==
Solution:
<langsyntaxhighlight lang="groovy">def printMultTable = { size = 12 ->
assert size > 1
Line 3,700 ⟶ 4,347:
}
 
printMultTable()</langsyntaxhighlight>
 
{{out}}
Line 3,718 ⟶ 4,365:
12| 144</pre>
 
=={{header|GW-BASIC}}==
{{trans|Modula-2}}
{{works with|PC-BASIC|any}}
<lang qbasic>
10 ' Multiplication Tables
20 LET N% = 12
30 FOR J% = 1 TO N% - 1
40 PRINT USING "###"; J%;
50 PRINT " ";
60 NEXT J%
70 PRINT USING "###"; N%
80 FOR J% = 0 TO N% - 1
90 PRINT "----";
100 NEXT J%
110 PRINT "+"
120 FOR I% = 1 TO N%
130 FOR J% = 1 TO N%
140 IF J% < I% THEN PRINT " "; ELSE PRINT USING "###"; I% * J%;: PRINT " ";
150 NEXT J%
160 PRINT "| "; USING "##"; I%
170 NEXT I%
</lang>
{{out}}
<pre>
1 2 3 4 5 6 7 8 9 10 11 12
------------------------------------------------+
1 2 3 4 5 6 7 8 9 10 11 12 | 1
4 6 8 10 12 14 16 18 20 22 24 | 2
9 12 15 18 21 24 27 30 33 36 | 3
16 20 24 28 32 36 40 44 48 | 4
25 30 35 40 45 50 55 60 | 5
36 42 48 54 60 66 72 | 6
49 56 63 70 77 84 | 7
64 72 80 88 96 | 8
81 90 99 108 | 9
100 110 120 | 10
121 132 | 11
144 | 12
</pre>
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Data.Maybe (fromMaybe, maybe)
 
------------------- MULTIPLICATION TABLE -----------------
Line 3,794 ⟶ 4,402:
gap = replicate w ' '
rows = (maybe gap (rjust w ' ' . show) =<<) <$> xs
rjust n c = (drop . length) <*> (replicate n c <>)</langsyntaxhighlight>
{{Out}}
<pre> 13 14 15 16 17 18 19 20
Line 3,832 ⟶ 4,440:
 
Or, more roughly and directly:
<langsyntaxhighlight lang="haskell">import Data.List (groupBy)
import Data.Function (on)
import Control.Monad (join)
Line 3,842 ⟶ 4,450:
groupBy
(on (==) fst)
(filter (uncurry (>=)) $ join ((<*>) . fmap (,)) [1 .. 12])</langsyntaxhighlight>
{{Out}}
<pre>[1]
Line 3,858 ⟶ 4,466:
 
=={{header|hexiscript}}==
<langsyntaxhighlight lang="hexiscript">fun format n l
let n tostr n
while len n < l; let n (" " + n); endwhile
Line 3,876 ⟶ 4,484:
endfor
println ""
endfor</langsyntaxhighlight>
 
=={{header|HicEst}}==
<langsyntaxhighlight HicEstlang="hicest">WRITE(Row=1) " x 1 2 3 4 5 6 7 8 9 10 11 12"
DO line = 1, 12
WRITE(Row=line+2, Format='i2') line
Line 3,885 ⟶ 4,493:
WRITE(Row=line+2, Column=4*col, Format='i3') line*col
ENDDO
ENDDO</langsyntaxhighlight>
 
=={{header|HolyC}}==
{{trans|C}}
<langsyntaxhighlight lang="holyc">U8 i, j, n = 12;
for (j = 1; j <= n; j++)
if (j != n)
Line 3,909 ⟶ 4,517:
Print("%3d ", i * j);
Print("| %d\n", i);
}</langsyntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
<langsyntaxhighlight Iconlang="icon">procedure main()
lim := 13
wid := 5
Line 3,918 ⟶ 4,526:
every (i := 1 to lim) &
writes(right( i||" |" | (j := 1 to lim, if j < i then "" else i*j) | "\n",wid)) # table content and triangle
end </langsyntaxhighlight>
 
The above example is a somewhat exaggerated example of contractions.
Line 3,940 ⟶ 4,548:
12 | 144 156
13 | 169 </pre>
 
=={{Header|Insitux}}==
<syntaxhighlight lang="insitux">
(var pad-num (comp str (pad-left " " 4)))
 
(join "\n"
(for y (range 1 13)
(... str "x" (pad-num y)
(for x (range 1 13)
(if (> y x)
" "
(pad-num (* x y)))))))
</syntaxhighlight>
{{out}}
<pre>
x 1 1 2 3 4 5 6 7 8 9 10 11 12
x 2 4 6 8 10 12 14 16 18 20 22 24
x 3 9 12 15 18 21 24 27 30 33 36
x 4 16 20 24 28 32 36 40 44 48
x 5 25 30 35 40 45 50 55 60
x 6 36 42 48 54 60 66 72
x 7 49 56 63 70 77 84
x 8 64 72 80 88 96
x 9 81 90 99 108
x 10 100 110 120
x 11 121 132
x 12 144
</pre>
 
=={{header|J}}==
<langsyntaxhighlight lang="j"> multtable=: <:/~ * */~
format=: 'b4.0' 8!:2 ]
(('*' ; ,.) ,. ({. ; ])@format@multtable) >:i.12
Line 3,960 ⟶ 4,596:
│11│ 121 132│
│12│ 144│
└──┴────────────────────────────────────────────────┘</langsyntaxhighlight>
 
That said, note that <code>*/~</code> is the core primitive used to construct a multiplication table and this is a general technique so that, for example, <code>+/~</code> would make an addition table. The rest is just to make it look pretty (and to blank out the lower triangle -- we use a less than or equal table (<code><:/~</code>) to control that, and format zeros as spaces to blank them out).
 
=={{header|Java}}==
<langsyntaxhighlight Javalang="java">public class MultiplicationTable {
public static void main(String[] args) {
for (int i = 1; i <= 12; i++)
Line 3,984 ⟶ 4,620:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 4,005 ⟶ 4,641:
=={{header|JavaScript}}==
 
===Imperative Unicode output ===
The following example works with any (modern) JavaScript runtime:
 
<syntaxhighlight lang="javascript" lines>
<lang html4strict><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
function timesTable(){
let output = "";
const size = 12;
for(let i = 1; i <= size; i++){
output += i.toString().padStart(3);
output += i !== size ? " " : "\n";
}
for(let i = 0; i <= size; i++)
output += i !== size ? "════" : "╕\n";
 
for(let i = 1; i <= size; i++){
for(let j = 1; j <= size; j++){
output += j < i
? " "
: (i * j).toString().padStart(3) + " ";
}
output += `│ ${i}\n`;
}
return output;
}
</syntaxhighlight>
 
{{out}}
<pre>
1 2 3 4 5 6 7 8 9 10 11 12
════════════════════════════════════════════════╕
1 2 3 4 5 6 7 8 9 10 11 12 │ 1
4 6 8 10 12 14 16 18 20 22 24 │ 2
9 12 15 18 21 24 27 30 33 36 │ 3
16 20 24 28 32 36 40 44 48 │ 4
25 30 35 40 45 50 55 60 │ 5
36 42 48 54 60 66 72 │ 6
49 56 63 70 77 84 │ 7
64 72 80 88 96 │ 8
81 90 99 108 │ 9
100 110 120 │ 10
121 132 │ 11
144 │ 12
</pre>
 
=== HTML tables ===
The following examples require a browser or browser-like environment:
 
====Imperative====
<syntaxhighlight lang="html4strict"><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<title>12 times table</title>
<script type='text/javascript'>
 
function multiplication_table(n, target) {
var table = document.createElement('table');
Line 4,047 ⟶ 4,728:
target.appendChild(table);
}
 
</script>
<style type='text/css'>
Line 4,058 ⟶ 4,738:
<div id='target'></div>
</body>
</html></langsyntaxhighlight>
 
{{out}} (minus the style):
<div><table><tr><th>x</th><th>1</th><th>2</th><th>3</th><th>4</th><th>5</th><th>6</th><th>7</th><th>8</th><th>9</th><th>10</th><th>11</th><th>12</th></tr><tr><th>1</th><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td><td>8</td><td>9</td><td>10</td><td>11</td><td>12</td></tr><tr><th>2</th><td> </td><td>4</td><td>6</td><td>8</td><td>10</td><td>12</td><td>14</td><td>16</td><td>18</td><td>20</td><td>22</td><td>24</td></tr><tr><th>3</th><td> </td><td> </td><td>9</td><td>12</td><td>15</td><td>18</td><td>21</td><td>24</td><td>27</td><td>30</td><td>33</td><td>36</td></tr><tr><th>4</th><td> </td><td> </td><td> </td><td>16</td><td>20</td><td>24</td><td>28</td><td>32</td><td>36</td><td>40</td><td>44</td><td>48</td></tr><tr><th>5</th><td> </td><td> </td><td> </td><td> </td><td>25</td><td>30</td><td>35</td><td>40</td><td>45</td><td>50</td><td>55</td><td>60</td></tr><tr><th>6</th><td> </td><td> </td><td> </td><td> </td><td> </td><td>36</td><td>42</td><td>48</td><td>54</td><td>60</td><td>66</td><td>72</td></tr><tr><th>7</th><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td>49</td><td>56</td><td>63</td><td>70</td><td>77</td><td>84</td></tr><tr><th>8</th><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td>64</td><td>72</td><td>80</td><td>88</td><td>96</td></tr><tr><th>9</th><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td>81</td><td>90</td><td>99</td><td>108</td></tr><tr><th>10</th><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td>100</td><td>110</td><td>120</td></tr><tr><th>11</th><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td>121</td><td>132</td></tr><tr><th>12</th><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td>144</td></tr></table></div>
 
====Functional====
=====ES5=====
<langsyntaxhighlight JavaScriptlang="javascript">(function (m, n) {
 
// [m..n]
function range(m, n) {
Line 4,078 ⟶ 4,758:
return [].concat.apply([], xs.map(f));
}
 
var rng = range(m, n),
lstTable = [['x'].concat( rng )]
.concat(mb(rng, function (x) {
return [[x].concat(mb(rng, function (y) {
return y < x ? [''] : [x * y]; // triangle only
}))]}));
Line 4,112 ⟶ 4,789:
// or simply stringified as JSON
JSON.stringify(lstTable);
})(1, 12);</syntaxhighlight>
})(1, 12);</lang>
 
{{out}}
Line 4,146 ⟶ 4,822:
|}
 
<langsyntaxhighlight JavaScriptlang="javascript">[["x",1,2,3,4,5,6,7,8,9,10,11,12],
[1,1,2,3,4,5,6,7,8,9,10,11,12],
[2,"",4,6,8,10,12,14,16,18,20,22,24],
Line 4,158 ⟶ 4,834:
[10,"","","","","","","","","",100,110,120],
[11,"","","","","","","","","","",121,132],
[12,"","","","","","","","","","","",144]]</langsyntaxhighlight>
 
=====ES6=====
<langsyntaxhighlight JavaScriptlang="javascript">(() => {
"use strict";
 
Line 4,234 ⟶ 4,910:
// MAIN ---
return main();
})();</langsyntaxhighlight>
{{Out}}
{| class="wikitable" style="text-align:center;width:33em;height:33em;table-layout:fixed"
Line 4,264 ⟶ 4,940:
|}
 
=={{header|jq}}==
<syntaxhighlight lang="jq">
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
 
def multiplication($n):
($n*$n|tostring|length) as $len
| ["x", range(0; $n + 1)] | map(lpad($len)) | join(" "),
(["", range(0; $n + 1)] | map($len*"-") | join(" ")),
( range(0; $n + 1) as $i
| [$i,
range(0; $n + 1) as $j
| if $j>=$i then $i*$j else "" end]
| map(lpad($len))
| join(" ") ) ;
 
multiplication(12)
</syntaxhighlight>
{{output}}
<pre>
x 0 1 2 3 4 5 6 7 8 9 10 11 12
--- --- --- --- --- --- --- --- --- --- --- --- --- ---
0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 2 3 4 5 6 7 8 9 10 11 12
2 4 6 8 10 12 14 16 18 20 22 24
3 9 12 15 18 21 24 27 30 33 36
4 16 20 24 28 32 36 40 44 48
5 25 30 35 40 45 50 55 60
6 36 42 48 54 60 66 72
7 49 56 63 70 77 84
8 64 72 80 88 96
9 81 90 99 108
10 100 110 120
11 121 132
12 144
</pre>
=={{header|Jsish}}==
<langsyntaxhighlight lang="javascript">/* Multiplication tables, is Jsish */
var m, n, tableSize = 12;
 
Line 4,285 ⟶ 4,996:
}
}
printf('\n');</langsyntaxhighlight>
 
{{out}}
Line 4,313 ⟶ 5,024:
 
=={{header|Julia}}==
<langsyntaxhighlight Julialang="julia">using Printf
 
println(" X | 1 2 3 4 5 6 7 8 9 10 11 12")
Line 4,326 ⟶ 5,037:
print(" ")
end
end</langsyntaxhighlight>
 
{{out}}
Line 4,345 ⟶ 5,056:
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.0.6
 
fun main(args: Array<String>) {
Line 4,356 ⟶ 5,067:
println()
}
}</langsyntaxhighlight>
 
{{out}}
Line 4,380 ⟶ 5,091:
Outputs are visible in http://lambdaway.free.fr/lambdawalks/?view=multiplication_table
 
<langsyntaxhighlight lang="scheme">
{def format
{lambda {:w :c}
Line 4,421 ⟶ 5,132:
3) {make_table {operation pow} 6 10}
 
</syntaxhighlight>
</lang>
 
=={{header|Lasso}}==
<langsyntaxhighlight lang="lasso">define printTimesTables(max::integer) => {
local(result) = ``
local(padSize) = string(#max*#max)->size + 1
Line 4,452 ⟶ 5,163:
}
 
printTimesTables(12)</langsyntaxhighlight>
 
{{out}}
Line 4,469 ⟶ 5,180:
12| 144</pre>
 
=={{header|Liberty BASIC}}==
<lang lb>Print " | 1 2 3 4 5 6 7 8 9 10 11 12"
Print "--+------------------------------------------------------------"
 
For i = 1 To 12
nums$ = Right$(" " + str$(i), 2) + "|"
For ii = 1 To 12
If i <= ii Then
If ii >= 1 Then
nums$ = nums$ + Left$(" ", (5 - Len(str$(i * ii))))
End If
nums$ = nums$ + str$(i * ii)
Else
nums$ = nums$ + " "
End If
Next ii
Print nums$
Next i</lang>
{{out}}
<pre>
| 1 2 3 4 5 6 7 8 9 10 11 12
--+------------------------------------------------------------
1| 1 2 3 4 5 6 7 8 9 10 11 12
2| 4 6 8 10 12 14 16 18 20 22 24
3| 9 12 15 18 21 24 27 30 33 36
4| 16 20 24 28 32 36 40 44 48
5| 25 30 35 40 45 50 55 60
6| 36 42 48 54 60 66 72
7| 49 56 63 70 77 84
8| 64 72 80 88 96
9| 81 90 99 108
10| 100 110 120
11| 121 132
12| 144
</pre>
 
=={{header|Logo}}==
{{works with|UCB Logo}}
<langsyntaxhighlight lang="logo">to mult.table :n
type "| | for [i 2 :n] [type form :i 4 0] (print)
(print)
Line 4,520 ⟶ 5,196:
 
mult.table 12
</syntaxhighlight>
</lang>
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">io.write( " |" )
for i = 1, 12 do
io.write( string.format( "%#5d", i ) )
Line 4,540 ⟶ 5,216:
end
io.write( "\n" )
end</langsyntaxhighlight>
<pre> | 1 2 3 4 5 6 7 8 9 10 11 12
----------------------------------------------------------------
Line 4,558 ⟶ 5,234:
=={{header|M2000 Interpreter}}==
Using jagged array (arrays of arrays)
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module CheckIt {
Dim Base 1, A(12)
Line 4,585 ⟶ 5,261:
}
CheckIt
</syntaxhighlight>
</lang>
 
Final loop can be this, using Each() and r1 as pointer to array.
Line 4,620 ⟶ 5,296:
 
=={{header|Maple}}==
<langsyntaxhighlight lang="maple">printf(" ");
for i to 12 do
printf("%-3d ", i);
Line 4,637 ⟶ 5,313:
end if
end do
end do</langsyntaxhighlight>
{{out}}
<pre>
Line 4,657 ⟶ 5,333:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">Grid[{{Range[12]//Column,Grid[UpperTriangularize[KroneckerProduct[Range[12],Range[12]]]/.{0->""}]}}]</langsyntaxhighlight>
{{out}}
<pre>1 1 2 3 4 5 6 7 8 9 10 11 12
Line 4,675 ⟶ 5,351:
timesTable.m: (creates Times Table of N degree)
 
<langsyntaxhighlight MATLABlang="matlab">function table = timesTable(N)
table = [(0:N); (1:N)' triu( kron((1:N),(1:N)') )];
end</langsyntaxhighlight>
 
A minimally vectorized version of the above code:
 
<langsyntaxhighlight MATLABlang="matlab">function table = timesTable(N)
 
%Generates a column vector with integers from 1 to N
Line 4,697 ⟶ 5,373:
table = [columnLabels; rowLabels triu(table)];
end</langsyntaxhighlight>
{{out}}
Line 4,721 ⟶ 5,397:
 
=={{header|Maxima}}==
<langsyntaxhighlight Maximalang="maxima">for i: 1 thru 12 do (
for j: 1 thru 12 do (
if j>=i or j=1 then printf(true, "~4d", i*j) else printf(true, " ")
),
printf(true, "~%")
);</langsyntaxhighlight>
 
Constructing a function to handle cases like this one
=={{header|Microsoft Small Basic}}==
[[File:Multiplication table.png|thumb|Formatted output using table_form]]
{{trans|Modula-2}}
<syntaxhighlight lang="maxima">
<lang microsoftsmallbasic>
/* Auxiliar function */
n = 12
aux_table(n,k):=append([k],makelist(0,i,1,k-1),makelist(k*i,i,k,n))$
For j = 1 To n - 1
 
TextWindow.CursorLeft = (j - 1) * 4 + (3 - Text.GetLength(j))
/* Function to construct the formatted table */
TextWindow.Write(j)
table_mult(n):=block(
TextWindow.Write(" ")
append([makelist(i,i,0,n)],makelist(aux_table(n,k),k,1,n)),
EndFor
makelist(at(%%[i],0=""),i,2,length(%%)),
TextWindow.CursorLeft = (n - 1) * 4 + (3 - Text.GetLength(n))
table_form(%%))$
TextWindow.Write(n)
 
TextWindow.WriteLine("")
/* Test case */
For j = 0 To n - 1
table_mult(12);
TextWindow.Write("----")
</syntaxhighlight>
EndFor
TextWindow.WriteLine("+")
For i = 1 To n
For j = 1 To n
If j < i Then
TextWindow.Write(" ")
Else
TextWindow.CursorLeft = (j - 1) * 4 + (3 - Text.GetLength(i * j))
TextWindow.Write(i * j)
TextWindow.Write(" ")
EndIf
EndFor
TextWindow.Write("| ")
TextWindow.CursorLeft = n * 4 + (4 - Text.GetLength(i))
TextWindow.Write(i)
TextWindow.WriteLine("")
EndFor
</lang>
{{out}}
<pre>
1 2 3 4 5 6 7 8 9 10 11 12
------------------------------------------------+
1 2 3 4 5 6 7 8 9 10 11 12 | 1
4 6 8 10 12 14 16 18 20 22 24 | 2
9 12 15 18 21 24 27 30 33 36 | 3
16 20 24 28 32 36 40 44 48 | 4
25 30 35 40 45 50 55 60 | 5
36 42 48 54 60 66 72 | 6
49 56 63 70 77 84 | 7
64 72 80 88 96 | 8
81 90 99 108 | 9
100 110 120 | 10
121 132 | 11
144 | 12
</pre>
 
=={{header|МК-61/52}}==
<syntaxhighlight lang="text">П0 КИП0 КИП4 КИП5 ИП4 ИП5 * С/П
ИП5 ИП0 - x=0 03
ИП4 ИП0 - x#0 22 ИП4 П5 БП 02
С/П</langsyntaxhighlight>
 
''Input'': 12 С/П ...
Line 4,804 ⟶ 5,446:
=={{header|Modula-2}}==
{{works with|ADW Modula-2|any (Compile with the linker option ''Console Application'').}}
<langsyntaxhighlight lang="modula2">
MODULE MultiplicationTables;
 
Line 4,844 ⟶ 5,486:
END;
END MultiplicationTables.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 4,865 ⟶ 5,507:
=={{header|MOO}}==
This quick example is designed to demonstrate raw MOO. In other words it does not use any of the helper functions available in popular DBs such as LambdaMOO.
<langsyntaxhighlight lang="moo">
@verb me:@tables none none none rxd
@program me:@tables
Line 4,891 ⟶ 5,533:
endfor
.
</syntaxhighlight>
</lang>
 
LambdaMOO string utilities version:
<langsyntaxhighlight lang="moo">
@program me:@tables
player:tell(" | 1 2 3 4 5 6 7 8 9 10 11 12");
Line 4,906 ⟶ 5,548:
endfor
.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 4,927 ⟶ 5,569:
 
=={{header|MUMPS}}==
<langsyntaxhighlight MUMPSlang="mumps">MULTTABLE(SIZE)
;Print out a multiplication table
;SIZE is the size of the multiplication table to make
Line 4,947 ⟶ 5,589:
..WRITE:((A-1)>=(D-2))&((D-2)>=1) ?((A-1)*5),$JUSTIFY((D-2)*(A-1),MW)
KILL MW,D,A,BAR
QUIT</langsyntaxhighlight>
 
{{out}}
Line 4,966 ⟶ 5,608:
11 | 121 132
12 | 144</pre>
 
=={{header|N/t/roff}}==
Works with gnu nroff. Please note that the script example contains tab characters which are essential for the correct tabular output.
<syntaxhighlight lang="nroff">
.nf
.ta T 2mR
.nr x 1 1
.nr y 2 1
.nr p 0
.while (\n[x] <= 12) \{\
.if (\n[x]<10) \0\c
\n[x]\c
.if (\n[x]=1) \c
.while (\n[y] <= 12) \{\
.nr p \n[x]*\n[y]
.ie (\n[y]>=\n[x]) \n[p] \c
.el \c
.nr y +1
.\}
.br
.nr x +1
.nr y 1 1
.\}
</syntaxhighlight>
{{out}}
<pre>
1 2 3 4 5 6 7 8 9 10 11 12
2 4 6 8 10 12 14 16 18 20 22 24
3 9 12 15 18 21 24 27 30 33 36
4 16 20 24 28 32 36 40 44 48
5 25 30 35 40 45 50 55 60
6 36 42 48 54 60 66 72
7 49 56 63 70 77 84
8 64 72 80 88 96
9 81 90 99 108
10 100 110 120
11 121 132
12 144
</pre>
 
=={{header|Neko}}==
<syntaxhighlight lang="actionscript">/**
<lang ActionScript>/**
Multiplication table, in Neko
Tectonics:
Line 5,009 ⟶ 5,690:
$print("\n");
j += 1;
}</langsyntaxhighlight>
 
{{out}}
Line 5,032 ⟶ 5,713:
=={{header|Nim}}==
{{trans|C}}
<langsyntaxhighlight lang="nim">import strfmt
 
const n = 12
Line 5,043 ⟶ 5,724:
for j in 1..n:
stdout.write if j<i: " " else: "{:3d} ".fmt(i*j)
echo "| {:2d}".fmt(i)</langsyntaxhighlight>
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 10 11 12
Line 5,063 ⟶ 5,744:
{{trans|C}}
 
<langsyntaxhighlight lang="ocaml">let () =
let max = 12 in
let fmax = float_of_int max in
Line 5,081 ⟶ 5,762:
print_newline()
done;
print_newline()</langsyntaxhighlight>
 
=={{header|PARI/GP}}==
Quick and dirty one-liner:
<langsyntaxhighlight lang="parigp">for(y=1,12,printf("%2Ps| ",y);for(x=1,12,print1(if(y>x,"",x*y)"\t"));print)</langsyntaxhighlight>
 
=={{header|Pascal}}==
Line 5,091 ⟶ 5,772:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">our $max = 12;
our $width = length($max**2) + 1;
 
Line 5,100 ⟶ 5,781:
foreach "$i|", map { $_ >= $i and $_*$i } 1..$max;
print "\n";
}</langsyntaxhighlight>
 
{{out}}
Line 5,122 ⟶ 5,803:
=={{header|Phix}}==
{{Trans|Ada}}
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" | "</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">col</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">12</span> <span style="color: #008080;">do</span>
Line 5,134 ⟶ 5,815:
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre style="font-size: 8px">
Line 5,152 ⟶ 5,833:
12| 144
</pre>
 
=={{header|Phixmonti}}==
<syntaxhighlight lang="Phixmonti">/# Rosetta Code problem: https://rosettacode.org/wiki/Multiplication_tables
by Galileo, 11/2022 #/
 
def tab 9 tochar print enddef
 
tab 12 for print tab endfor nl
tab '-' 12 8 * repeat print nl
12 for
dup print tab 8 tochar print "|" print
dup for
over * print tab
endfor
drop nl
endfor</syntaxhighlight>
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 10 11 12
------------------------------------------------------------------------------------------------
1 |1
2 |2 4
3 |3 6 9
4 |4 8 12 16
5 |5 10 15 20 25
6 |6 12 18 24 30 36
7 |7 14 21 28 35 42 49
8 |8 16 24 32 40 48 56 64
9 |9 18 27 36 45 54 63 72 81
10 |10 20 30 40 50 60 70 80 90 100
11 |11 22 33 44 55 66 77 88 99 110 121
12 |12 24 36 48 60 72 84 96 108 120 132 144
 
=== Press any key to exit ===</pre>
 
=={{header|Picat}}==
<langsyntaxhighlight Picatlang="picat">go =>
N=12,
make_table(N),
Line 5,178 ⟶ 5,892:
nl
end,
nl.</langsyntaxhighlight>
 
{{out}}
Line 5,195 ⟶ 5,909:
11 | 121 132
12 | 144</pre>
 
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLilang="picoli/th">sp>(de mulTable (N)
(space 4)
(for X N
Line 5,211 ⟶ 5,924:
(prinl) ) )
 
(mulTable 12)</langsyntaxhighlight>
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 10 11 12
Line 5,229 ⟶ 5,942:
 
=={{header|PL/I}}==
<syntaxhighlight lang="pl/i">
<lang PL/I>
/* 12 x 12 multiplication table. */
 
Line 5,244 ⟶ 5,957:
 
end multiplication_table;
</syntaxhighlight>
</lang>
 
Result:
 
<langpre>
1 2 3 4 5 6 7 8 9 10 11 12
_________________________________________________
Line 5,263 ⟶ 5,976:
11 | 121 132
12 | 144
</langpre>
 
=={{header|PowerShell}}==
<langsyntaxhighlight lang="powershell"># For clarity
$Tab = "`t"
Line 5,286 ⟶ 5,999:
# Combine them all together
) -join $Tab
}</langsyntaxhighlight>
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 10 11 12
Line 5,302 ⟶ 6,015:
12 144</pre>
<b>A more general solution</b>
<langsyntaxhighlight lang="powershell">function Get-TimesTable ( [int]$Size )
{
# For clarity
Line 5,327 ⟶ 6,040:
}
Get-TimesTable 18</langsyntaxhighlight>
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Line 5,350 ⟶ 6,063:
 
=={{header|Prolog}}==
<langsyntaxhighlight lang="prolog">make_table(S,E) :-
print_header(S,E),
make_table_rows(S,E),
Line 5,382 ⟶ 6,095:
print_num(X) :- X < 10, format(' ~p', X).
print_num(X) :- between(10,99,X), format(' ~p', X).
print_num(X) :- X > 99, format(' ~p', X).</langsyntaxhighlight>
{{out}}
<pre>
Line 5,404 ⟶ 6,117:
 
?-</pre>
 
=={{header|PureBasic}}==
<lang PureBasic>Procedure PrintMultiplicationTable(maxx, maxy)
sp = Len(Str(maxx*maxy)) + 1
trenner$ = "+"
For l1 = 1 To maxx + 1
For l2 = 1 To sp
trenner$ + "-"
Next
trenner$ + "+"
Next
header$ = "|" + RSet("x", sp) + "|"
For a = 1 To maxx
header$ + RSet(Str(a), sp)
header$ + "|"
Next
PrintN(trenner$)
PrintN(header$)
PrintN(trenner$)
For y = 1 To maxy
line$ = "|" + RSet(Str(y), sp) + "|"
For x = 1 To maxx
If x >= y
line$ + RSet(Str(x*y), sp)
Else
line$ + Space(sp)
EndIf
line$ + "|"
Next
PrintN(line$)
Next
PrintN(trenner$)
EndProcedure
 
OpenConsole()
PrintMultiplicationTable(12, 12)
Input()</lang>
 
Ouput similar to ALGOL 68
 
=={{header|Python}}==
===Procedural===
<langsyntaxhighlight lang="python">>>> size = 12
>>> width = len(str(size**2))
>>> for row in range(-1,size+1):
Line 5,474 ⟶ 6,148:
11│ 121 132
12│ 144
>>> </langsyntaxhighlight>
 
The above works with Python 3.X, which uses Unicode strings by default. <br>
Line 5,486 ⟶ 6,160:
and then again, for comparison, as an equivalent '''list monad''' expression (''mulTable2'' function):
 
<langsyntaxhighlight lang="python">'''Multiplication table
 
1. by list comprehension (mulTable ),
Line 5,588 ⟶ 6,262:
 
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre>By list comprehension (mulTable):
Line 5,624 ⟶ 6,298:
{{Trans|Haskell}}
{{Works with|Python|3.7}}
<langsyntaxhighlight lang="python">'''Generalised multiplication tables'''
 
import collections
Line 5,890 ⟶ 6,564:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre> 13 14 15 16 17 18 19 20
Line 5,930 ⟶ 6,604:
=={{header|Quackery}}==
 
<langsyntaxhighlight Quackerylang="quackery"> [ swap number$
tuck size -
times sp echo$ ] is echo-rj ( n n --> )
Line 5,949 ⟶ 6,623:
[ dip dup
* 4 echo-rj ] ]
cr drop ] ]</langsyntaxhighlight>
 
{{Out}}
Line 5,969 ⟶ 6,643:
 
=={{header|R}}==
<syntaxhighlight lang="r">
<lang r>
multiplication_table <- function(n=12)
{
Line 5,980 ⟶ 6,654:
}
multiplication_table()
</syntaxhighlight>
</lang>
 
=={{header|Racket}}==
 
<syntaxhighlight lang="racket">
<lang Racket>
#lang racket
 
Line 5,995 ⟶ 6,669:
(show-line (cons y (for/list ([x (in-range 1 13)])
(if (<= y x) (* x y) "")))))
</syntaxhighlight>
</lang>
 
{{out}}
Line 6,016 ⟶ 6,690:
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" line>(my $f = "%{$_}s" given my $width = ($_**2).chars ) given my $max = 12;
{{trans|Perl}}
 
say '×'.fmt($f) ~ ' ┃ ' ~ (1..$max).fmt($f);
{{works with|Rakudo Star|2010.08}}
say '━' x $width ~ '━╋' ~ '━' x $max × (1+$width);
 
<lang perl6>my $max = 12;
my $width = chars $max**2;
my $f = "%{$width}s";
say 'x'.fmt($f), '│ ', (1..$max).fmt($f);
say '─' x $width, '┼', '─' x $max*$width + $max;
for 1..$max -> $i {
say $i.fmt($f), ~ ' ', ~ ( $i ≤ $_ ?? $i×$_ !! '' for 1..$max ).fmt($f);
}</syntaxhighlight>
for 1..$max -> $j {
$i <= $j ?? $i*$j !! '';
}
).fmt($f);
}</lang>
 
{{out}}
<pre>
Line 6,053 ⟶ 6,717:
 
=={{header|REBOL}}==
<langsyntaxhighlight REBOLlang="rebol">REBOL [
Title: "12x12 Multiplication Table"
URL: http://rosettacode.org/wiki/Print_a_Multiplication_Table
Line 6,085 ⟶ 6,749:
 
print rejoin [ crlf "How about " size: 20 "?" crlf ]
-- .row " x " 1 -- repeat y size [.row p3 y y] --</langsyntaxhighlight>
 
{{out}} (only 12x12 shown):
Line 6,107 ⟶ 6,771:
 
=={{header|REXX}}==
<langsyntaxhighlight REXXlang="rexx">/*REXX program displays a NxN multiplication table (in a boxed grid) to the terminal.*/
parse arg sz . /*obtain optional argument from the CL.*/
if sz=='' | sz=="," then sz= 12 /*Not specified? Then use the default.*/
Line 6,129 ⟶ 6,793:
top: $= '┌'__"┬"copies(___'┬', sz); call dap "┐"; ?= arg(1); say $; call hdr; return
sep: $= '├'__"┼"copies(___'┼', sz); call dap "┤"; say $; return
bot: $= '└'__"┴"copies(___'┴', sz); call dap "┘"; say $; return</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default input of: &nbsp; &nbsp; <tt> 12 </tt>}}
<pre>
Line 6,201 ⟶ 6,865:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
multiplication_table(12)
func multiplication_table n
Line 6,213 ⟶ 6,877:
next
func fsize x,n return string(x) + copy(" ",n-len(string(x)))
</syntaxhighlight>
</lang>
 
Output
<langsyntaxhighlight lang="ring">
| 1 2 3 4 5 6 7 8 9 10 11 12
----+-------------------------------------------------
Line 6,231 ⟶ 6,895:
11 | 121 132
12 | 144
</syntaxhighlight>
</lang>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">def multiplication_table(n)
puts " |" + (" %3d" * n) % [*1..n]
puts "----+" + "----" * n
Line 6,245 ⟶ 6,909:
end
 
multiplication_table 12</langsyntaxhighlight>
 
{{out}}
Line 6,264 ⟶ 6,928:
12 | 144
</pre>
 
=={{header|Run BASIC}}==
<lang Runbasic>html "<TABLE border=1 ><TR bgcolor=silver align=center><TD><TD>1<TD>2<TD>3<TD>4<TD>5<TD>6<TD>7<TD>8<TD>9<TD>10<TD>11<TD>12</td></TR>"
For i = 1 To 12
html "<TR align=right><TD>";i;"</td>"
For ii = 1 To 12
html "<td width=25>"
If ii >= i Then html i * ii
html "</td>"
Next ii
next i
html "</table>"
</lang>Output:
<TABLE border=1 ><TR bgcolor=silver align=center><TD><TD>1<TD>2<TD>3<TD>4<TD>5<TD>6<TD>7<TD>8<TD>9<TD>10<TD>11<TD>12</td></TR><TR align=right><TD>1</td><td width=25>1</td><td width=25>2</td><td width=25>3</td><td width=25>4</td><td width=25>5</td><td width=25>6</td><td width=25>7</td><td width=25>8</td><td width=25>9</td><td width=25>10</td><td width=25>11</td><td width=25>12</td><TR align=right><TD>2</td><td width=25></td><td width=25>4</td><td width=25>6</td><td width=25>8</td><td width=25>10</td><td width=25>12</td><td width=25>14</td><td width=25>16</td><td width=25>18</td><td width=25>20</td><td width=25>22</td><td width=25>24</td><TR align=right><TD>3</td><td width=25></td><td width=25></td><td width=25>9</td><td width=25>12</td><td width=25>15</td><td width=25>18</td><td width=25>21</td><td width=25>24</td><td width=25>27</td><td width=25>30</td><td width=25>33</td><td width=25>36</td><TR align=right><TD>4</td><td width=25></td><td width=25></td><td width=25></td><td width=25>16</td><td width=25>20</td><td width=25>24</td><td width=25>28</td><td width=25>32</td><td width=25>36</td><td width=25>40</td><td width=25>44</td><td width=25>48</td><TR align=right><TD>5</td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25>25</td><td width=25>30</td><td width=25>35</td><td width=25>40</td><td width=25>45</td><td width=25>50</td><td width=25>55</td><td width=25>60</td><TR align=right><TD>6</td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25>36</td><td width=25>42</td><td width=25>48</td><td width=25>54</td><td width=25>60</td><td width=25>66</td><td width=25>72</td><TR align=right><TD>7</td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25>49</td><td width=25>56</td><td width=25>63</td><td width=25>70</td><td width=25>77</td><td width=25>84</td><TR align=right><TD>8</td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25>64</td><td width=25>72</td><td width=25>80</td><td width=25>88</td><td width=25>96</td><TR align=right><TD>9</td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25>81</td><td width=25>90</td><td width=25>99</td><td width=25>108</td><TR align=right><TD>10</td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25>100</td><td width=25>110</td><td width=25>120</td><TR align=right><TD>11</td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25>121</td><td width=25>132</td><TR align=right><TD>12</td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25></td><td width=25>144</td></table>
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">const LIMIT: i32 = 12;
 
fn main() {
Line 6,300 ⟶ 6,950:
println!("| {}", i);
}
}</langsyntaxhighlight>
 
or, in terms of map:
 
<langsyntaxhighlight lang="rust">fn main() {
let xs = (1..=12)
.map(|a| {
Line 6,320 ⟶ 6,970:
 
println!("{}", xs.join("\n"))
}</langsyntaxhighlight>
 
=={{header|Scala}}==
<langsyntaxhighlight lang="scala">
//Multiplication Table
print("%5s".format("|"))
Line 6,342 ⟶ 6,992:
println("")
}
</syntaxhighlight>
</lang>
 
=== case ===
<langsyntaxhighlight lang="scala">
implicit def intToString(i: Int) = i.toString
val cell = (x:String) => print("%5s".format(x))
Line 6,364 ⟶ 7,014:
}
}
</syntaxhighlight>
</lang>
 
=={{header|Scheme}}==
Line 6,370 ⟶ 7,020:
A better implementation of <tt>iota</tt> is provided by SRFI-1 [http://srfi.schemers.org/srfi-1/srfi-1.html].
 
<langsyntaxhighlight lang="scheme">
(define iota
(lambda (count start step)
Line 6,397 ⟶ 7,047:
(loop (+ count 1)
(cdr numbers)))))))
</syntaxhighlight>
</lang>
 
<pre>
Line 6,417 ⟶ 7,067:
=={{header|Scilab}}==
{{works with|Scilab|5.5.1}}
<syntaxhighlight lang="scilab"> nmax=12, xx=3
s= blanks(xx)+" |"
for j=1:nmax
Line 6,438 ⟶ 7,088:
end
printf("%s\n",s)
end</langsyntaxhighlight>
{{out}}
<pre> | 1 2 3 4 5 6 7 8 9 10 11 12
Line 6,456 ⟶ 7,106:
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
const proc: main is func
Line 6,479 ⟶ 7,129:
writeln("|" <& i lpad 3);
end for;
end func;</langsyntaxhighlight>
 
{{out}}
Line 6,500 ⟶ 7,150:
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">var max = 12
var width = (max**2 -> len+1)
 
Line 6,512 ⟶ 7,162:
{ |i| 
say fmt_row("#{i}┃", {|j| i <= j ? i*j : ''}.map(1..max)...)
} << 1..max</langsyntaxhighlight>
{{out}}
<pre>
Line 6,533 ⟶ 7,183:
=={{header|Simula}}==
{{trans|ALGOL W}}
<langsyntaxhighlight lang="simula">begin
integer i, j;
outtext( " " );
Line 6,549 ⟶ 7,199:
outimage
end;
end</langsyntaxhighlight>
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 10 11 12
Line 6,567 ⟶ 7,217:
 
=={{header|Swift}}==
<langsyntaxhighlight lang="swift">import Foundation
 
let size = 12
Line 6,587 ⟶ 7,237:
printRow( with: i, upto: size)
}
</syntaxhighlight>
</lang>
 
=={{header|Tailspin}}==
<langsyntaxhighlight lang="tailspin">
templates formatN&{width:}
[ 1..$width -> ' ', '$;'... ] -> '$(last-$width+1..last)...;' !
Line 6,602 ⟶ 7,252:
'$ -> formatN&{width:2};|$:1..($-1)*4 -> ' ';$:$..12 -> $*$row -> formatN&{width:4};
' ! \) -> !OUT::write
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 6,622 ⟶ 7,272:
 
=={{header|Tcl}}==
<langsyntaxhighlight lang="tcl">puts " x\u2502 1 2 3 4 5 6 7 8 9 10 11 12"
puts \u0020\u2500\u2500\u253c[string repeat \u2500 48]
for {set i 1} {$i <= 12} {incr i} {
Line 6,632 ⟶ 7,282:
}
puts ""
}</langsyntaxhighlight>
{{out}}
<pre>
Line 6,650 ⟶ 7,300:
12│ 144
</pre>
 
=={{header|True BASIC}}==
<lang qbasic>PRINT " X| 1 2 3 4 5 6 7 8 9 10 11 12"
PRINT "---+------------------------------------------------"
 
FOR i = 1 TO 12
LET nums$ = (" " & STR$(i))[LEN(" " & STR$(i))-3+1:maxnum] & "|"
FOR j = 1 TO 12
IF i <= j THEN
IF j >= 1 THEN LET nums$ = nums$ & (" ")[1:(4-LEN(STR$(i*j)))]
LET nums$ = nums$ & STR$(i*j)
ELSE
LET nums$ = nums$ & " "
END IF
NEXT j
PRINT nums$
NEXT i
PRINT
END</lang>
 
=={{header|TUSCRIPT}}==
<langsyntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
x=y="1'2'3'4'5'6'7'8'9'10'11'12"
Line 6,690 ⟶ 7,321:
PRINT col,cnt
ENDLOOP
</syntaxhighlight>
</lang>
{{out}}
<pre style='height:30ex;overflow:scroll'>
Line 6,709 ⟶ 7,340:
== {{header|TypeScript}} ==
{{trans|Modula-2}}
<langsyntaxhighlight lang="javascript">
// Multiplication tables
 
function intToString(n: number, wdth: number): string {
sn = Math.floor(n).toString();
len = sn.length;
return (wdth < len ? "#".repeat(wdth) : " ".repeat(wdth - len) + sn);
}
 
var n = 12;
console.clear();
for (j = 1; j < n; j++)
process.stdout.write(intToString(j.toString().padStart(3, 3' ') + " ");
console.log(intToString(n.toString().padStart(3, 3' '));
console.log("----".repeat(n) + "+");
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++)
process.stdout.write(j < i ? " " : intToString(i * j, 3) + " ");
" " : (i * j).toString().padStart(3, ' ') + " ");
console.log("| " + intToString(i, 2));
console.log("| " + i.toString().padStart(2, ' '));
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 6,747 ⟶ 7,373:
144 | 12
</pre>
 
=={{header|uBasic/4tH}}==
{{trans|BBC BASIC}}
<lang>For R = 1 To 12
Print R;Tab(R * 5);
For C = R To 12
Print Using "_____";R * C;
Next
Print
Next</lang>
{{out}}
<pre>1 1 2 3 4 5 6 7 8 9 10 11 12
2 4 6 8 10 12 14 16 18 20 22 24
3 9 12 15 18 21 24 27 30 33 36
4 16 20 24 28 32 36 40 44 48
5 25 30 35 40 45 50 55 60
6 36 42 48 54 60 66 72
7 49 56 63 70 77 84
8 64 72 80 88 96
9 81 90 99 108
10 100 110 120
11 121 132
12 144
 
0 OK, 0:105</pre>
 
=={{header|Ursala}}==
It's no more difficult to express the general case than the size 12 case, so
a table generating function parameterized by the size is used.
<syntaxhighlight lang="ursala">
<lang Ursala>
#import std
#import nat
Line 6,789 ⟶ 7,390:
 
main = table 12
</syntaxhighlight>
</lang>
A better way of using Ursala to make tables would be with the <code>tbl</code> library included with
the standard package, which can generate LaTeX code for arbitrary heading hierarchies and typesetting options, but here it is in ASCII art.
Line 6,809 ⟶ 7,410:
</pre>
 
=={{header|VBAVBScript}}==
<syntaxhighlight lang="vb">
 
function pad(s,n) if n<0 then pad= right(space(-n) & s ,-n) else pad= left(s& space(n),n) end if
<lang vb>
End Function
Option Explicit
Sub print(s):
 
On Error Resume Next
Sub Multiplication_Tables()
WScript.stdout.Write (s)
Dim strTemp As String, strBuff As String
If err= &h80070006& Then WScript.Echo " Please run this script with CScript": WScript.quit
Dim i&, j&, NbDigits As Byte
 
'You can adapt the following const :
Const NB_END As Byte = 12
 
Select Case NB_END
Case Is < 10: NbDigits = 3
Case 10 To 31: NbDigits = 4
Case 31 To 100: NbDigits = 5
Case Else: MsgBox "Number too large": Exit Sub
End Select
strBuff = String(NbDigits, " ")
For i = 1 To NB_END
strTemp = Right(strBuff & i, NbDigits)
For j = 2 To NB_END
If j < i Then
strTemp = strTemp & strBuff
Else
strTemp = strTemp & Right(strBuff & j * i, NbDigits)
End If
Next j
Debug.Print strTemp
Next i
End Sub
For i=1 To 12
</lang>
print pad(i,-4)
Next
print vbCrLf & String(48,"_")
For i=1 To 12
print vbCrLf
For j=1 To 12
if j<i Then print Space(4) Else print pad(i*j,-4)
Next
print "|"& pad(i,-2)
Next
</syntaxhighlight>
{{out}}
<small>
<pre> 1 2 3 4 5 6 7 8 9 10 11 12
2 4 6 8 10 12 14 16 18 20 22 24
3 9 12 15 18 21 24 27 30 33 36
4 16 20 24 28 32 36 40 44 48
5 25 30 35 40 45 50 55 60
6 36 42 48 54 60 66 72
7 49 56 63 70 77 84
8 64 72 80 88 96
9 81 90 99 108
10 100 110 120
11 121 132
12 144</pre>
 
=={{header|Visual Basic}}==
{{works with|Visual Basic|VB6 Standard}}
<lang vb>Sub Main()
Const nmax = 12, xx = 3
Const x = xx + 1
Dim i As Integer, j As Integer, s As String
s = String(xx, " ") & " |"
For j = 1 To nmax
s = s & Right(String(x, " ") & j, x)
Next j
Debug.Print s
s = String(xx, "-") & " +"
For j = 1 To nmax
s = s & " " & String(xx, "-")
Next j
Debug.Print s
For i = 1 To nmax
s = Right(String(xx, " ") & i, xx) & " |"
For j = 1 To nmax
If j >= i _
Then s = s & Right(String(x, " ") & i * j, x) _
Else s = s & String(x, " ")
Next j
Debug.Print s
Next i
End Sub 'Main</lang>
{{Out}}
<pre>
| 1 2 3 4 5 6 7 8 9 10 11 12
________________________________________________
--- + --- --- --- --- --- --- --- --- --- --- --- ---
1 | 1 2 3 4 5 6 7 8 9 10 11 12| 1
2 | 4 6 8 10 12 14 16 18 20 22 24| 2
3 | 9 12 15 18 21 24 27 30 33 36| 3
4 | 16 20 24 28 32 36 40 44 48| 4
5 | 25 30 35 40 45 50 55 60| 5
6 | 36 42 48 54 60 66 72| 6
7 | 49 56 63 70 77 84| 7
8 | 64 72 80 88 96| 8
9 | 81 90 99 108| 9
10 | 100 110 120|10
11 | 121 132|11
12 | 144|12
</pre>
</small>
 
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "./fmt" for Fmt
 
var nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
Line 6,910 ⟶ 7,460:
var nums2 = nums.map { |n| (n >= i) ? (n * i).toString : " " }.toList
Fmt.print("$3d | $4s", i, nums2)
}</langsyntaxhighlight>
 
{{out}}
Line 6,928 ⟶ 7,478:
11 | 121 132
12 | 144
</pre>
 
=={{header|XBasic}}==
{{trans|Modula-2}}
{{works with|Windows XBasic}}
<lang xbasic>
PROGRAM "multiplicationtables"
VERSION "0.0001"
 
DECLARE FUNCTION Entry()
 
FUNCTION Entry()
$N = 12
FOR j@@ = 1 TO $N - 1
PRINT FORMAT$("### ", j@@);
NEXT j@@
PRINT FORMAT$("###", $N)
FOR j@@ = 0 TO $N - 1
PRINT "----";
NEXT j@@
PRINT "+"
FOR i@@ = 1 TO $N
FOR j@@ = 1 TO $N
IF j@@ < i@@ THEN
PRINT " ";
ELSE
PRINT FORMAT$("### ", i@@ * j@@);
END IF
NEXT j@@
PRINT "|"; FORMAT$(" ##", i@@)
NEXT i@@
END FUNCTION
END PROGRAM
</lang>
{{out}}
<pre>
1 2 3 4 5 6 7 8 9 10 11 12
------------------------------------------------+
1 2 3 4 5 6 7 8 9 10 11 12 | 1
4 6 8 10 12 14 16 18 20 22 24 | 2
9 12 15 18 21 24 27 30 33 36 | 3
16 20 24 28 32 36 40 44 48 | 4
25 30 35 40 45 50 55 60 | 5
36 42 48 54 60 66 72 | 6
49 56 63 70 77 84 | 7
64 72 80 88 96 | 8
81 90 99 108 | 9
100 110 120 | 10
121 132 | 11
144 | 12
</pre>
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">include c:\cxpl\codes;
int X, Y;
[Format(4, 0);
Line 6,994 ⟶ 7,494:
CrLf(0);
];
]</langsyntaxhighlight>
 
{{out}}
Line 7,013 ⟶ 7,513:
12| . . . . . . . . . . . . . . . . . . . . . . 144
</pre>
 
=={{header|Yabasic}}==
{{works with|QBasic}}
<lang freebasic>print " X| 1 2 3 4 5 6 7 8 9 10 11 12"
print "---+------------------------------------------------"
 
for i = 1 to 12
nums$ = right$(" " + str$(i), 3) + "|"
for j = 1 to 12
if i <= j then
if j >= 1 then
nums$ = nums$ + left$(" ", (4 - len(str$(i * j))))
end if
nums$ = nums$ + str$(i * j)
else
nums$ = nums$ + " "
end if
next j
print nums$
next i</lang>
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">fcn multiplicationTable(n){
w,fmt := (n*n).numDigits, " %%%dd".fmt(w).fmt; // eg " %3".fmt
header:=[1..n].apply(fmt).concat(); // 1 2 3 4 ...
Line 7,044 ⟶ 7,524:
[a..n].pump(String,'*(a),fmt).println();
}
}(12);</langsyntaxhighlight>
{{out}}
<pre>
9,476

edits