Multiplication tables: Difference between revisions
m
→{{header|Wren}}: Minor tidy
(Added Tailspin solution) |
m (→{{header|Wren}}: Minor tidy) |
||
(74 intermediate revisions by 29 users not shown) | |||
Line 8:
Only print the top half triangle of products.
<br><br>
=={{header|11l}}==
{{trans|C}}
<syntaxhighlight lang="11l">V n = 12
L(j) 1..n
print(‘#3’.format(j), end' ‘ ’)
print(‘│’)
L 1..n
print(‘────’, end' ‘’)
print(‘┼───’)
L(i) 1..n
L(j) 1..n
print(I j < i {‘ ’} E ‘#3 ’.format(i * j), end' ‘’)
print(‘│ ’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|360 Assembly}}==
<
MULTTABL CSECT
USING MULTTABL,R12
Line 69 ⟶ 103:
PORT DC C'--+-------------------------------------------------'
YREGS
END MULTTABL</
{{out}}
<pre> | 1 2 3 4 5 6 7 8 9 10 11 12
Line 85 ⟶ 119:
11| 121 132
12| 144</pre>
=={{header|8080 Assembly}}==
<syntaxhighlight lang="8080asm"> org 100h
lxi h,output
;;; Make the header
call skip ; Four spaces,
mvi m,'|' ; separator,
inx h
lxi d,0C01h ; 12 fields starting at 1
fnum: mov a,e ; Field number
call num
inr e
dcr d ; If not 12 yet, next field number
jnz fnum
call nl ; Newline
mvi a,'-' ; Four dashes,
mvi b,4
call bchr
mvi m,'+' ; Plus,
inx h
mvi b,12*4 ; and 12*4 more dashes
call bchr
call nl ; Newline
;;; Write the 12 lines
mvi d,1 ; Start at line 1,
line: mov a,d ; Add the line number
call num
mvi m,'|' ; separator
inx h
mvi e,1 ; Start at column 1
mvi c,0 ; Cumulative sum at C
field: mov a,c ; Add line number giving next column
add d
mov c,a
mov a,e ; If column >= line, we need to print
cmp d
mov a,c ; the current total
cc skip ; skip field if column >= line
cnc num ; print field if column < line
inr e ; next column
mov a,e
cpi 13 ; column 13?
jnz field ; If not, next field on line
call nl ; But if so, add newline
inr d ; next line
mov a,d
cpi 13 ; line 13?
jnz line ; If not, next line
mvi m,'$' ; Write a CP/M string terminator,
mvi c,9 ; And use CP/M to print the string
lxi d,output
jmp 5
;;; Add the character in A to the string at HL, B times
bchr: mov m,a
inx h
dcr b
jnz bchr
ret
;;; Add newline to string at HL
nl: mvi m,13 ; CR
inx h
mvi m,10 ; LF
inx h
ret
;;; Add four spaces to string at HL (skip field)
skip: mvi b,' '
mov m,b
inx h
mov m,b
inx h
mov m,b
inx h
mov m,b
inx h
ret
;;; Add 3-digit number in A to string at HL
num: mvi m,' ' ; Separator space
inx h
ana a ; Clear carry
mvi b,100 ; 100s digit
call dspc
mvi b,10 ; 10s digit
call dspc
mvi b,1 ; 1s digit
dspc: jc dgt ; If carry, we need a digit
cmp b ; >= digit?
jnc dgt ; If not, we need a digit
mvi m,' ' ; Otherwise, fill with space
inx h
cmc ; Return with carry off
ret
dgt: mvi m,'0'-1 ; Calculate digit
dloop: inr m ; Increment digit
sub b ; while B can be subtracted
jnc dloop
add b
inx h
ret
output: equ $</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|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program multtable64.s */
Line 239 ⟶ 391:
.include "../includeARM64.inc"
</syntaxhighlight>
{{Output}}
<pre>
Line 255 ⟶ 407:
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
</pre>
=={{header|Action!}}==
<syntaxhighlight lang="action!">PROC PrintRight(BYTE num,size)
BYTE i
IF num<10 THEN
size==-1
ELSEIF num<100 THEN
size==-2
ELSE
size==-3
FI
FOR i=1 TO size
DO
Put(' )
OD
PrintB(num)
RETURN
PROC Main()
BYTE ARRAY colw=[1 1 1 2 2 2 2 2 2 3 3 3]
BYTE i,j,x,w
;clear screen
Put(125)
;draw frame
Position(1,3)
FOR i=1 TO 38
DO Put($12) OD
FOR j=2 TO 15
DO
Position(36,j)
Put($7C)
OD
Position(36,3)
Put($13)
;draw numbers
FOR j=1 TO 12
DO
x=1
FOR i=1 TO 12
DO
w=colw(i-1)
IF i>=j THEN
IF j=1 THEN
Position(x,j+1)
PrintRight(i*j,w)
FI
IF i=12 THEN
Position(37,j+3)
PrintRight(j,2)
FI
Position(x,j+3)
PrintRight(i*j,w)
FI
x==+w+1
OD
OD
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Multiplication_tables.png Screenshot from Atari 8-bit computer]
<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|ActionScript}}==
<syntaxhighlight lang="actionscript">
package {
Line 338 ⟶ 571:
}
</syntaxhighlight>
=={{header|Ada}}==
<syntaxhighlight lang="ada">
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
Line 367 ⟶ 600:
end loop;
end Multiplication_Table;
</syntaxhighlight>
<pre>
| 1 2 3 4 5 6 7 8 9 10 11 12
Line 387 ⟶ 620:
=={{header|Agena}}==
{{Trans|ALGOL_W}}
<
# print a school style multiplication table
# NB: print outputs a newline at the end, write and printf do not
Line 400 ⟶ 633:
od;
print()
epocs</
{{out}}
<pre>
Line 425 ⟶ 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}} -->
<
INT max = 12;
INT width = ENTIER(log(max)*2)+1;
Line 443 ⟶ 676:
OD;
printf(($gl$, hr))
)</
{{out}}
<pre>
Line 465 ⟶ 698:
=={{header|ALGOL W}}==
<
% print a school style multiplication table %
i_w := 3; s_w := 0; % set output formating %
Line 478 ⟶ 711:
end;
end.</
{{out}}
<pre>
Line 496 ⟶ 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===
<
repeat with x from 0 to n
end repeat
return table as string
Line 517 ⟶ 795:
-- Handler/Function for formatting fixed width integer string.
on f(x)
end f</
{{out}}
<pre>"
Line 541 ⟶ 819:
{{trans|JavaScript}} (ES5 functional version)
<syntaxhighlight lang="applescript">------------------- MULTIPLICATION TABLE -----------------
--
on multiplicationTable(lower, upper)
tell ap(my tableText, my mulTable)
end tell
end multiplicationTable
-- mulTable :: [Int]-> [[Int]]
on mulTable(axis)
script column
Line 553 ⟶ 837:
on |λ|(y)
if y < x then
else
end if
end |λ|
end script
{{x} & map(row, axis)}
end |λ|
end script
end
-- tableText :: [[Int]] -> String
on tableText(
set colWidth to 1 + (length of (|last|(|last|(rows)) as string))
set cell to replicate(colWidth, space)
script tableLine
on |λ|(
script tableCell
on |λ|(int)
(characters (-
end |λ|
end script
intercalate(
end |λ|
end script
set legend to {{"x"} & axis}
intercalate(linefeed, map(tableLine, legend & {{}} & rows))
end tableText
--------------------------- TEST -------------------------
on run
multiplicationTable(1, 12) & linefeed & linefeed & ¬
multiplicationTable(30, 40)
end run
-------------------- GENERIC FUNCTIONS -------------------
-- ap :: (a -> b -> c) -> (a -> b) -> a -> c
on ap(f, g)
-- The application of f x to g x
script go
property mf : |λ| of mReturn(f)
property mg : |λ| of mReturn(g)
on |λ|(x)
mf(x, mg(x))
end |λ|
end script
end ap
-- concatMap :: (a -> [b]) -> [a] -> [b]
Line 600 ⟶ 908:
return lst
end concatMap
-- enumFromTo :: Int -> Int -> [Int]
Line 614 ⟶ 923:
return lst
end enumFromTo
-- foldl :: (a -> b -> a) -> a -> [b] -> a
Line 626 ⟶ 936:
end tell
end foldl
-- intercalate :: Text -> [Text] -> Text
Line 634 ⟶ 945:
return strJoined
end intercalate
-- justifyRight :: Int -> Char -> Text -> Text
Line 643 ⟶ 955:
end if
end justifyRight
-- last :: [a] -> a
on |last|(xs)
item -1 of xs
end |last|
-- map :: (a -> b) -> [a] -> [b]
Line 655 ⟶ 974:
end tell
end map
-- Lift 2nd class handler function into 1st class script wrapper
Line 666 ⟶ 986:
end script
end if
end mReturn
-- replicate :: Int -> String -> String
on replicate(n, s)
set out to ""
if n < 1 then return out
set dbl to s
repeat while (n > 1)
if (n mod 2) > 0 then set out to out & dbl
set n to (n div 2)
set dbl to (dbl & dbl)
end repeat
return out & dbl
end replicate</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
Line 680 ⟶ 1,016:
10 100 110 120
11 121 132
12 144
x 30 31 32 33 34 35 36 37 38 39 40
30 900 930 960 990 1020 1050 1080 1110 1140 1170 1200
31 961 992 1023 1054 1085 1116 1147 1178 1209 1240
32 1024 1056 1088 1120 1152 1184 1216 1248 1280
33 1089 1122 1155 1188 1221 1254 1287 1320
34 1156 1190 1224 1258 1292 1326 1360
35 1225 1260 1295 1330 1365 1400
36 1296 1332 1368 1404 1440
37 1369 1406 1443 1480
38 1444 1482 1520
39 1521 1560
40 1600</pre>
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
/* ARM assembly Raspberry PI */
Line 867 ⟶ 1,217:
</syntaxhighlight>
=={{header|Arturo}}==
<syntaxhighlight lang="rebol">mulTable: function [n][
print [" |"] ++ map 1..n => [pad to :string & 3]
print "----+" ++ join map 1..n => "----"
loop 1..n 'x [
prints (pad to :string x 3) ++ " |"
if x>1 -> loop 1..x-1 'y [prints " "]
loop x..n 'y [prints " " ++ pad to :string x*y 3]
print ""
]
]
mulTable 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|AutoHotkey}}==
<
Gui, Margin, 0, 0
Gui, Font, s9, Fixedsys
Line 905 ⟶ 1,286:
}
GuiControl,, Edit2, %Table%
Return</
Message box shows:
<pre> x | 1 2 3 4 5 6 7 8 9 10 11 12
Line 924 ⟶ 1,305:
=={{header|AutoIt}}==
<
$tableupto=12
$table=""
Line 943 ⟶ 1,324:
Next
Next
msgbox(0,"Multiplication Tables",$table)</
=={{header|AWK}}==
<syntaxhighlight lang="awk">
BEGIN {
for(i=1;i<=12;i++){
Line 955 ⟶ 1,336:
print
}
}</
{{out}}
<pre>
Line 974 ⟶ 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.
<
ClrDraw
For(I,1,10)
Line 991 ⟶ 1,372:
DispGraph
getKeyʳ
Fix 4</
Approximate output:
Line 1,008 ⟶ 1,389:
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
<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}}===
<syntaxhighlight lang="qbasic">CLS
'header row
Line 1,035 ⟶ 1,940:
PRINT o$;
NEXT
NEXT</
{{out}}
Line 1,055 ⟶ 1,960:
</pre>
==={{header|Run BASIC}}===
<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|
{{trans|Modula-2}}
{{works with|TinyBasic}}
<syntaxhighlight lang="basic">
10 REM MULTIPLICATION TABLES
20 LET N=12
30 REM TO ALIGN NUMBERS TO THE RIGHT
40 REM ASSUME THAT N IS AT MOST TWO-DIGIT.
50 LET J=1
60 PRINT " ";
70 IF J<10 THEN PRINT " ";
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|
<syntaxhighlight lang="qbasic">PRINT " X| 1 2 3 4 5 6 7 8 9 10 11 12"
PRINT "---+------------------------------------------------"
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)
LET nums$ = nums$ & " "
END IF
PRINT nums$
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|Yabasic}}===
<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$(" " + 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</syntaxhighlight>
=={{header|Batch File}}==
<
setlocal enabledelayedexpansion
Line 1,132 ⟶ 2,286:
for /l %%A in (1,1,%numspaces%) do set "space=!space! "
goto :EOF
::/The Functions.</
{{Out}}
<pre>
Line 1,151 ⟶ 2,305:
Press any key to continue . . .</pre>
=={{header|Befunge}}==
<
w^p2<y|!`+66:+1,+*84*"\"!:g25$_,#!>#:<$$_^#!:-1g10/+55\-**<<
"$9"^x>$55+,51g1+:66+`#@_055+68*\>\#<1#*-#9:#5_$"+---">:#,_$</
{{out}}
Line 1,196 ⟶ 2,326:
11| 121 132
12| 144</pre>
=={{header|BQN}}==
<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>).
<syntaxhighlight lang="bqn">Table ← {
m ← •Repr¨ ×⌜˜1+↕𝕩 # The numbers, formatted individually
main ← ⟨ # Bottom part: three sections
>(-⌈10⋆⁼𝕩)↑¨⊏m # Original numbers
𝕩⥊'|' # Divider
∾˘(-1+⌈10⋆⁼𝕩×𝕩)↑¨(≤⌜˜↕𝕩)/¨m # Multiplied numbers, padded and joined
⟩
head ← ' '¨⌾⊑ ⊏¨ main # Header: first row but with space left of |
∾ >⟨head, "-+-"⊣¨¨head, main⟩ # Header, divider, and main
}
•Out˘ Table 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|Bracmat}}==
<
= high i j row row2 matrix padFnc tmp
, celPad leftCelPad padFnc celDashes leftDashes
Line 1,253 ⟶ 2,415:
)
& out$(multiplicationTable$12)
& done;</
{{out}}
<pre> X| 1 2 3 4 5 6 7 8 9 10 11 12
Line 1,271 ⟶ 2,433:
=={{header|C}}==
<
int main(void)
Line 1,287 ⟶ 2,449:
return 0;
}</
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 10 11 12
Line 1,305 ⟶ 2,467:
=={{header|C sharp}}==
<
namespace multtbl
Line 1,343 ⟶ 2,505:
}
}
</syntaxhighlight>
{{out}}
Line 1,367 ⟶ 2,529:
and formats the table columns.
<
#include <iomanip>
#include <cmath> // for log10()
Line 1,444 ⟶ 2,606:
return 0;
}
</syntaxhighlight>
{{out}}
Line 1,478 ⟶ 2,640:
=={{header|Chef}}==
<
Prints out a multiplication table.
Line 1,542 ⟶ 2,704:
Pour contents of the 2nd mixing bowl into the 2nd baking dish.
Serves 2.</
{{out}}
Line 1,563 ⟶ 2,725:
This is more generalized.
Any size can be used and the table will be formatted appropriately.
<
trange (range 1 (inc size))
fmt-width (+ (.length (str (* size size))) 1)
Line 1,576 ⟶ 2,738:
(for [j trange] j))))))]
(println s)))
</syntaxhighlight>
{{out}}
Line 1,595 ⟶ 2,757:
=={{header|COBOL}}==
<
program-id. multiplication-table.
Line 1,641 ⟶ 2,803:
goback.
end program multiplication-table.
</syntaxhighlight>
{{out}}
<pre>prompt$ cobc -xj multiplication-table.cob
Line 1,659 ⟶ 2,821:
=={{header|CoffeeScript}}==
<
print_multiplication_tables = (n) ->
width = 4
Line 1,691 ⟶ 2,853:
print_multiplication_tables 12
</syntaxhighlight>
{{out}}
Line 1,713 ⟶ 2,875:
=={{header|Common Lisp}}==
<
(do ((m 0 (if (= 12 m) 0 (1+ m)))
(n 0 (if (= 12 m) (1+ n) n)))
Line 1,730 ⟶ 2,892:
(format t "~4,D" (* m n))
(format t " "))))))
</syntaxhighlight>
Output:
<pre>
Line 1,752 ⟶ 2,914:
=={{header|D}}==
{{trans|PicoLisp}}
<
import std.stdio, std.array, std.range, std.algorithm;
Line 1,760 ⟶ 2,922:
writefln("%4d" ~ " ".replicate(4 * (y - 1)) ~ "%(%4d%)", y,
iota(y, n + 1).map!(x => x * y));
}</
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 10 11 12
Line 1,778 ⟶ 2,940:
=={{header|DCL}}==
<
$ h = f$fao( "!4* " )
$ r = 0
Line 1,803 ⟶ 2,965:
$ write sys$output f$fao( "!4SL", r ) + o
$ r = r + 1
$ if r .le. max then $ goto loop1</
{{out}}
<pre>$ @multiplication_tables
Line 1,825 ⟶ 2,987:
=={{header|Delphi}}==
{{trans|DWScript}}
<
{$APPTYPE CONSOLE}
Line 1,854 ⟶ 3,016:
Writeln;
end;
end.</
=={{header|Draco}}==
<syntaxhighlight lang="draco">/* Print N-by-N multiplication table */
proc nonrec multab(byte n) void:
byte i,j;
/* write header */
write(" |");
for i from 1 upto n do write(i:4) od;
writeln();
write("----+");
for i from 1 upto n do write("----") od;
writeln();
/* write lines */
for i from 1 upto n do
write(i:4, "|");
for j from 1 upto n do
if i <= j then write(i*j:4)
else write(" ")
fi
od;
writeln()
od
corp
/* Print 12-by-12 multiplication table */
proc nonrec main() void: multab(12) corp</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|DWScript}}==
<
var row, col : Integer;
Line 1,876 ⟶ 3,081:
PrintLn('');
end;
</syntaxhighlight>
=={{header|E}}==
<
println(`{|style="border-collapse: collapse; text-align: right;"`)
println(`|`)
Line 1,893 ⟶ 3,098:
}
}
println("|}")</
Targets MediaWiki markup.
Line 2,085 ⟶ 3,290:
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
n = 12
numfmt 0 4
write " "
for i = 1 to n
.
write " "
for i = 1 to n
write "----"
.
for i = 1 to n
write "|"
for j = 1 to n
if j < i
write " "
else
.
.
.
</syntaxhighlight>
=={{header|EchoLisp}}==
<
(lib 'matrix)
Line 2,133 ⟶ 3,331:
(array-print (build-array 13 13 mtable))
</syntaxhighlight>
{{out}}
<pre>
Line 2,152 ⟶ 3,350:
=={{header|Elixir}}==
<
def multiplication_tables(n) do
IO.write " X |"
Line 2,167 ⟶ 3,365:
end
RC.multiplication_tables(12)</
{{out}}
Line 2,185 ⟶ 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">
-module( multiplication_tables ).
Line 2,213 ⟶ 3,443:
[io:fwrite("~5B", [Sum]) || {_Y, Sum} <- Uptos],
io:nl().
</syntaxhighlight>
{{out}}
<pre>
Line 2,234 ⟶ 3,464:
=={{header|Euphoria}}==
<
for i = 1 to 12 do
printf(1," %3d",i)
Line 2,251 ⟶ 3,481:
end for
puts(1,'\n')
end for</
{{out}}
Line 2,269 ⟶ 3,499:
12 144
</pre>
=={{header|Excel}}==
===LAMBDA===
Binding the name FNOVERHALFCARTESIANPRODUCT to the following lambda expression in the Name Manager of the Excel WorkBook:
(See [https://www.microsoft.com/en-us/research/blog/lambda-the-ultimatae-excel-worksheet-function/ LAMBDA: The ultimate Excel worksheet function])
{{Works with|Office 365 betas 2021}}
<syntaxhighlight lang="lisp">FNOVERHALFCARTESIANPRODUCT
=LAMBDA(f,
LAMBDA(n,
LET(
ixs, SEQUENCE(n, n, 1, 1),
REM, "1-based indices.",
x, 1 + MOD(ixs - 1, n),
y, 1 + QUOTIENT(ixs - 1, n),
IF(x >= y,
f(x)(y),
""
)
)
)
)</syntaxhighlight>
and also assuming the following generic bindings in the Name Manager for the WorkBook:
<syntaxhighlight lang="lisp">MUL
=LAMBDA(a, LAMBDA(b, a * b))
POW
=LAMBDA(n,
LAMBDA(e,
POWER(n, e)
)
)</syntaxhighlight>
(The single formula in cell '''B2''' below populates the whole 12*12 grid)
{{Out}}
{| class="wikitable"
|-
|||style="text-align:right; font-family:serif; font-style:italic; font-size:120%;"|fx
! colspan="13" style="text-align:left; vertical-align: bottom; font-family:Arial, Helvetica, sans-serif !important;"|=FNOVERHALFCARTESIANPRODUCT( MUL )(12)
|- style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff;"
|
| A
| B
| C
| D
| E
| F
| G
| H
| I
| J
| K
| L
| M
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 1
| x*y
| colspan="12" | applied over every unique pair in a cartesian product of [1..12] with itself
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 2
| style="text-align:right; font-weight:bold" | 1
| style="text-align:right; background-color:#cbcefb" | 1
| style="text-align:right" | 2
| style="text-align:right" | 3
| style="text-align:right" | 4
| style="text-align:right" | 5
| style="text-align:right" | 6
| style="text-align:right" | 7
| style="text-align:right" | 8
| style="text-align:right" | 9
| style="text-align:right" | 10
| style="text-align:right" | 11
| style="text-align:right" | 12
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 3
| style="text-align:right; font-weight:bold" | 2
|
| style="text-align:right" | 4
| style="text-align:right" | 6
| style="text-align:right" | 8
| style="text-align:right" | 10
| style="text-align:right" | 12
| style="text-align:right" | 14
| style="text-align:right" | 16
| style="text-align:right" | 18
| style="text-align:right" | 20
| style="text-align:right" | 22
| style="text-align:right" | 24
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 4
| style="text-align:right; font-weight:bold" | 3
|
|
| style="text-align:right" | 9
| style="text-align:right" | 12
| style="text-align:right" | 15
| style="text-align:right" | 18
| style="text-align:right" | 21
| style="text-align:right" | 24
| style="text-align:right" | 27
| style="text-align:right" | 30
| style="text-align:right" | 33
| style="text-align:right" | 36
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 5
| style="text-align:right; font-weight:bold" | 4
|
|
|
| style="text-align:right" | 16
| style="text-align:right" | 20
| style="text-align:right" | 24
| style="text-align:right" | 28
| style="text-align:right" | 32
| style="text-align:right" | 36
| style="text-align:right" | 40
| style="text-align:right" | 44
| style="text-align:right" | 48
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 6
| style="text-align:right; font-weight:bold" | 5
|
|
|
|
| style="text-align:right" | 25
| style="text-align:right" | 30
| style="text-align:right" | 35
| style="text-align:right" | 40
| style="text-align:right" | 45
| style="text-align:right" | 50
| style="text-align:right" | 55
| style="text-align:right" | 60
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 7
| style="text-align:right; font-weight:bold" | 6
|
|
|
|
|
| style="text-align:right" | 36
| style="text-align:right" | 42
| style="text-align:right" | 48
| style="text-align:right" | 54
| style="text-align:right" | 60
| style="text-align:right" | 66
| style="text-align:right" | 72
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 8
| style="text-align:right; font-weight:bold" | 7
|
|
|
|
|
|
| style="text-align:right" | 49
| style="text-align:right" | 56
| style="text-align:right" | 63
| style="text-align:right" | 70
| style="text-align:right" | 77
| style="text-align:right" | 84
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 9
| style="text-align:right; font-weight:bold" | 8
|
|
|
|
|
|
|
| style="text-align:right" | 64
| style="text-align:right" | 72
| style="text-align:right" | 80
| style="text-align:right" | 88
| style="text-align:right" | 96
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 10
| style="text-align:right; font-weight:bold" | 9
|
|
|
|
|
|
|
|
| style="text-align:right" | 81
| style="text-align:right" | 90
| style="text-align:right" | 99
| style="text-align:right" | 108
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 11
| style="text-align:right; font-weight:bold" | 10
|
|
|
|
|
|
|
|
|
| style="text-align:right" | 100
| style="text-align:right" | 110
| style="text-align:right" | 120
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 12
| style="text-align:right; font-weight:bold" | 11
|
|
|
|
|
|
|
|
|
|
| style="text-align:right" | 121
| style="text-align:right" | 132
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 13
| style="text-align:right; font-weight:bold" | 12
|
|
|
|
|
|
|
|
|
|
|
| style="text-align:right" | 144
|}
{| class="wikitable"
|-
|||style="text-align:right; font-family:serif; font-style:italic; font-size:120%;"|fx
! colspan="13" style="text-align:left; vertical-align: bottom; font-family:Arial, Helvetica, sans-serif !important;"|=FNOVERHALFCARTESIANPRODUCT( POW )(12)
|- style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff;"
|
| A
| B
| C
| D
| E
| F
| G
| H
| I
| J
| K
| L
| M
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 1
| x^y
| COLSPAN="12" | applied over every unique pair in a cartesian product of [1..12] with itself
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 2
| style="text-align:right; font-weight:bold" | 1
| style="text-align:right; background-color:#cbcefb" | 1
| style="text-align:right" | 2
| style="text-align:right" | 3
| style="text-align:right" | 4
| style="text-align:right" | 5
| style="text-align:right" | 6
| style="text-align:right" | 7
| style="text-align:right" | 8
| style="text-align:right" | 9
| style="text-align:right" | 10
| style="text-align:right" | 11
| style="text-align:right" | 12
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 3
| style="text-align:right; font-weight:bold" | 2
|
| style="text-align:right" | 4
| style="text-align:right" | 9
| style="text-align:right" | 16
| style="text-align:right" | 25
| style="text-align:right" | 36
| style="text-align:right" | 49
| style="text-align:right" | 64
| style="text-align:right" | 81
| style="text-align:right" | 100
| style="text-align:right" | 121
| style="text-align:right" | 144
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 4
| style="text-align:right; font-weight:bold" | 3
|
|
| style="text-align:right" | 27
| style="text-align:right" | 64
| style="text-align:right" | 125
| style="text-align:right" | 216
| style="text-align:right" | 343
| style="text-align:right" | 512
| style="text-align:right" | 729
| style="text-align:right" | 1000
| style="text-align:right" | 1331
| style="text-align:right" | 1728
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 5
| style="text-align:right; font-weight:bold" | 4
|
|
|
| style="text-align:right" | 256
| style="text-align:right" | 625
| style="text-align:right" | 1296
| style="text-align:right" | 2401
| style="text-align:right" | 4096
| style="text-align:right" | 6561
| style="text-align:right" | 10000
| style="text-align:right" | 14641
| style="text-align:right" | 20736
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 6
| style="text-align:right; font-weight:bold" | 5
|
|
|
|
| style="text-align:right" | 3125
| style="text-align:right" | 7776
| style="text-align:right" | 16807
| style="text-align:right" | 32768
| style="text-align:right" | 59049
| style="text-align:right" | 100000
| style="text-align:right" | 161051
| style="text-align:right" | 248832
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 7
| style="text-align:right; font-weight:bold" | 6
|
|
|
|
|
| style="text-align:right" | 46656
| style="text-align:right" | 117649
| style="text-align:right" | 262144
| style="text-align:right" | 531441
| style="text-align:right" | 1000000
| style="text-align:right" | 1771561
| style="text-align:right" | 2985984
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 8
| style="text-align:right; font-weight:bold" | 7
|
|
|
|
|
|
| style="text-align:right" | 823543
| style="text-align:right" | 2097152
| style="text-align:right" | 4782969
| style="text-align:right" | 10000000
| style="text-align:right" | 19487171
| style="text-align:right" | 35831808
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 9
| style="text-align:right; font-weight:bold" | 8
|
|
|
|
|
|
|
| style="text-align:right" | 16777216
| style="text-align:right" | 43046721
| style="text-align:right" | 100000000
| style="text-align:right" | 214358881
| style="text-align:right" | 429981696
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 10
| style="text-align:right; font-weight:bold" | 9
|
|
|
|
|
|
|
|
| style="text-align:right" | 387420489
| style="text-align:right" | 1000000000
| style="text-align:right" | 2357947691
| style="text-align:right" | 5159780352
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 11
| style="text-align:right; font-weight:bold" | 10
|
|
|
|
|
|
|
|
|
| style="text-align:right" | 10000000000
| style="text-align:right" | 25937424601
| style="text-align:right" | 61917364224
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 12
| style="text-align:right; font-weight:bold" | 11
|
|
|
|
|
|
|
|
|
|
| style="text-align:right" | 285311670611
| style="text-align:right" | 743008370688
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 13
| style="text-align:right; font-weight:bold" | 12
|
|
|
|
|
|
|
|
|
|
|
| style="text-align:right" | 8916100448256
|}
=={{header|F Sharp|F#}}==
Translation of C#
<syntaxhighlight lang="fsharp">
open System
Line 2,292 ⟶ 3,974:
multTable ()
</syntaxhighlight>
{{out}}
<pre>
Line 2,312 ⟶ 3,994:
=={{header|Factor}}==
<
IN: multiplication-table
Line 2,328 ⟶ 4,010:
" +" write
12 [ "----" write ] times nl
1 12 [a,b] [ print-row ] each ;</
<pre>
Line 2,348 ⟶ 4,030:
=={{header|FALSE}}==
<
[$p;! m: 2[$m;\>][" "1+]# [$13\>][$m;*p;!1+]#%"
"]l:
1[$13\>][$l;!1+]#%</
=={{header|Fantom}}==
<
class Main
{
Line 2,377 ⟶ 4,059:
}
}
</syntaxhighlight>
=={{header|Forth}}==
<
: multiplication-table
cr 2 spaces 13 2 do i 4 u.r loop
Line 2,390 ⟶ 4,072:
loop
loop ;
</syntaxhighlight>
=={{header|Fortran}}==
{{works with|Fortran|90 and later}}
<
implicit none
Line 2,412 ⟶ 4,094:
end do
end program multtable</
===Traditional approach===
Line 2,418 ⟶ 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">
Cast forth a twelve times table, suitable for chanting at school.
INTEGER I,J !Steppers.
Line 2,430 ⟶ 4,112:
3 WRITE (6,"(A)") ALINE !Print the text.
END !"One one is one! One two is two! One three is three!...
</syntaxhighlight>
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 2,447 ⟶ 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">
Cast forth a twelve times table, suitable for chanting at school.
INTEGER I,J !Steppers.
Line 2,458 ⟶ 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>
The output is the same, so instead, here are the generated FORMAT texts:
(I3,'|',0X,12I4)
Line 2,479 ⟶ 4,161:
===VAX FORTRAN===
<syntaxhighlight lang="fortran">
PROGRAM TABLES
IMPLICIT NONE
Line 2,504 ⟶ 4,186:
C
END
</
===FORTRAN-IV===
<
C
C Produce a formatted multiplication table of the kind memorised by rote
Line 2,540 ⟶ 4,222:
3 CONTINUE
C
END</
===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.
<
C
C Produce a formatted multiplication table of the kind memorised by rote
Line 2,576 ⟶ 4,258:
3 CONTINUE
C
END</
4 FORMAT(1x,24A1)</
| 1 2 3 4 5 6 7 8 9 10 11 12
--+------------------------------------------------
Line 2,591 ⟶ 4,273:
10| 100 110 120
11| 121 132
12| 144</
=={{header|Frink}}==
<
formatTable[a,"right"]</
{{out}}
Line 2,655 ⟶ 4,294:
11 121 132
12 144
</pre>
=={{header|Go}}==
<syntaxhighlight lang="go">
package main
Line 2,729 ⟶ 4,325:
fmt.Println("")
}
</syntaxhighlight>
=={{header|Groovy}}==
Solution:
<
assert size > 1
Line 2,751 ⟶ 4,347:
}
printMultTable()</
{{out}}
Line 2,769 ⟶ 4,365:
12| 144</pre>
=={{header|Haskell}}==
<
------------------- MULTIPLICATION TABLE -----------------
mulTable :: [Int] -> [[Maybe Int]]
mulTable xs =
(Nothing : labels) :
zipWith
(:)
[
where
upperMul x y
| x > y = Nothing
| otherwise = Just (x * y)
--------------------------- TEST -------------------------
main :: IO ()
main =
showTable . mulTable
<$> [ [13 .. 20],
[1 .. 12],
[95 .. 100]
]
------------------------ FORMATTING
showTable :: [[Maybe Int]] -> String
showTable xs = unlines $ head rows : [] : tail rows
where
w =
gap = replicate w ' '
rows = (maybe gap (rjust w ' ' . show) =<<) <$> xs
rjust n c = (drop . length) <*> (replicate n c <>)</syntaxhighlight>
{{Out}}
<pre> 13 14 15 16 17 18 19 20
Line 2,878 ⟶ 4,440:
Or, more roughly and directly:
<
import Data.Function (on)
import Control.Monad (join)
Line 2,888 ⟶ 4,450:
groupBy
(on (==) fst)
(filter (uncurry (>=)) $ join ((<*>) . fmap (,)) [1 .. 12])</
{{Out}}
<pre>[1]
Line 2,904 ⟶ 4,466:
=={{header|hexiscript}}==
<
let n tostr n
while len n < l; let n (" " + n); endwhile
Line 2,922 ⟶ 4,484:
endfor
println ""
endfor</
=={{header|HicEst}}==
<
DO line = 1, 12
WRITE(Row=line+2, Format='i2') line
Line 2,931 ⟶ 4,493:
WRITE(Row=line+2, Column=4*col, Format='i3') line*col
ENDDO
ENDDO</
=={{header|HolyC}}==
{{trans|C}}
<
for (j = 1; j <= n; j++)
if (j != n)
Line 2,955 ⟶ 4,517:
Print("%3d ", i * j);
Print("| %d\n", i);
}</
=={{header|Icon}} and {{header|Unicon}}==
<
lim := 13
wid := 5
Line 2,964 ⟶ 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 </
The above example is a somewhat exaggerated example of contractions.
Line 2,986 ⟶ 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}}==
<
format=: 'b4.0' 8!:2 ]
(('*' ; ,.) ,. ({. ; ])@format@multtable) >:i.12
Line 3,006 ⟶ 4,596:
│11│ 121 132│
│12│ 144│
└──┴────────────────────────────────────────────────┘</
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}}==
<
public static void main(String[] args) {
for (int i = 1; i <= 12; i++)
Line 3,030 ⟶ 4,620:
}
}
}</
{{out}}
<pre>
Line 3,051 ⟶ 4,641:
=={{header|JavaScript}}==
===
The following example works with any (modern) JavaScript runtime:
<syntaxhighlight lang="javascript" lines>
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 3,093 ⟶ 4,728:
target.appendChild(table);
}
</script>
<style type='text/css'>
Line 3,104 ⟶ 4,738:
<div id='target'></div>
</body>
</html></
{{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=====
<
// [m..n]
function range(m, n) {
Line 3,124 ⟶ 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 3,158 ⟶ 4,789:
// or simply stringified as JSON
JSON.stringify(lstTable);
})(1, 12);</syntaxhighlight>
{{out}}
Line 3,192 ⟶ 4,822:
|}
<
[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 3,204 ⟶ 4,834:
[10,"","","","","","","","","",100,110,120],
[11,"","","","","","","","","","",121,132],
[12,"","","","","","","","","","","",144]]</
=====ES6=====
<
// -------------- MULTIPLICATION TABLE ---------------
// multTable :: Int -> Int -> [[String]]
const multTable = m => n => {
const xs = enumFromTo(m)(n);
return [
[
...xs.flatMap(
x => [
[x, ...xs.flatMap(
y => y < x ?
[""]
) : [`${x * y}`]
)]
]
Line 3,225 ⟶ 4,860:
};
//
// main :: () -> IO String
const main = () =>
wikiTable({
"width:33em",
"height:33em",
"table-layout:fixed"
].join(";")
})(
multTable(1)(12)
);
//
// enumFromTo :: Int -> Int -> [Int]
Line 3,252 ⟶ 4,884:
}, (_, i) => m + i) : [];
// ------------------- FORMATTING --------------------
// wikiTable :: Dict -> [[a]] -> String
const wikiTable = opts =>
rows => {
const
style = ["class", "style"].reduce(
(a, k) => k in opts ? (
`${a}${k}="${opts[k]}" `
) : a, ""
),
body = rows.map((row, i) => {
const
cells = row.map(
x => `${x}` || " "
).join(" || ");
return `${i ? "|" : "!"} ${cells}`;
}).join("\n|-\n");
//
return main();
})();</
{{Out}}
{| class="wikitable" style="text-align:center;width:33em;height:33em;table-layout:fixed
! 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
|}
=={{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}}==
<
var m, n, tableSize = 12;
Line 3,335 ⟶ 4,996:
}
}
printf('\n');</
{{out}}
Line 3,363 ⟶ 5,024:
=={{header|Julia}}==
<
println(" X | 1 2 3 4 5 6 7 8 9 10 11 12")
Line 3,376 ⟶ 5,037:
print(" ")
end
end</
{{out}}
Line 3,395 ⟶ 5,056:
=={{header|Kotlin}}==
<
fun main(args: Array<String>) {
Line 3,406 ⟶ 5,067:
println()
}
}</
{{out}}
Line 3,430 ⟶ 5,091:
Outputs are visible in http://lambdaway.free.fr/lambdawalks/?view=multiplication_table
<
{def format
{lambda {:w :c}
Line 3,471 ⟶ 5,132:
3) {make_table {operation pow} 6 10}
</syntaxhighlight>
=={{header|Lasso}}==
<
local(result) = ``
local(padSize) = string(#max*#max)->size + 1
Line 3,502 ⟶ 5,163:
}
printTimesTables(12)</
{{out}}
Line 3,519 ⟶ 5,180:
12| 144</pre>
=={{header|Logo}}==
{{works with|UCB Logo}}
<
type "| | for [i 2 :n] [type form :i 4 0] (print)
(print)
Line 3,570 ⟶ 5,196:
mult.table 12
</syntaxhighlight>
=={{header|Lua}}==
<
for i = 1, 12 do
io.write( string.format( "%#5d", i ) )
Line 3,590 ⟶ 5,216:
end
io.write( "\n" )
end</
<pre> | 1 2 3 4 5 6 7 8 9 10 11 12
----------------------------------------------------------------
Line 3,608 ⟶ 5,234:
=={{header|M2000 Interpreter}}==
Using jagged array (arrays of arrays)
<syntaxhighlight lang="m2000 interpreter">
Module CheckIt {
Dim Base 1, A(12)
Line 3,635 ⟶ 5,261:
}
CheckIt
</syntaxhighlight>
Final loop can be this, using Each() and r1 as pointer to array.
Line 3,670 ⟶ 5,296:
=={{header|Maple}}==
<
for i to 12 do
printf("%-3d ", i);
Line 3,687 ⟶ 5,313:
end if
end do
end do</
{{out}}
<pre>
Line 3,706 ⟶ 5,332:
</pre>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
{{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
Line 3,721 ⟶ 5,346:
10 100 110 120
11 121 132
12 144</pre>
=={{header|MATLAB}} / {{header|Octave}}==
timesTable.m: (creates Times Table of N degree)
<
table = [(0:N); (1:N)' triu( kron((1:N),(1:N)') )];
end</
A minimally vectorized version of the above code:
<
%Generates a column vector with integers from 1 to N
Line 3,749 ⟶ 5,373:
table = [columnLabels; rowLabels triu(table)];
end</
{{out}}
Line 3,773 ⟶ 5,397:
=={{header|Maxima}}==
<
for j: 1 thru 12 do (
if j>=i or j=1 then printf(true, "~4d", i*j) else printf(true, " ")
),
printf(true, "~%")
);</
Constructing a function to handle cases like this one
[[File:Multiplication table.png|thumb|Formatted output using table_form]]
<syntaxhighlight lang="maxima">
/* Auxiliar function */
aux_table(n,k):=append([k],makelist(0,i,1,k-1),makelist(k*i,i,k,n))$
/* Function to construct the formatted table */
table_mult(n):=block(
append([makelist(i,i,0,n)],makelist(aux_table(n,k),k,1,n)),
makelist(at(%%[i],0=""),i,2,length(%%)),
table_form(%%))$
/* Test case */
table_mult(12);
</syntaxhighlight>
=={{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
С/П</
''Input'': 12 С/П ...
Line 3,856 ⟶ 5,446:
=={{header|Modula-2}}==
{{works with|ADW Modula-2|any (Compile with the linker option ''Console Application'').}}
<
MODULE MultiplicationTables;
Line 3,896 ⟶ 5,486:
END;
END MultiplicationTables.
</syntaxhighlight>
{{out}}
<pre>
Line 3,917 ⟶ 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.
<
@verb me:@tables none none none rxd
@program me:@tables
Line 3,943 ⟶ 5,533:
endfor
.
</syntaxhighlight>
LambdaMOO string utilities version:
<
@program me:@tables
player:tell(" | 1 2 3 4 5 6 7 8 9 10 11 12");
Line 3,958 ⟶ 5,548:
endfor
.
</syntaxhighlight>
{{out}}
<pre>
Line 3,979 ⟶ 5,569:
=={{header|MUMPS}}==
<
;Print out a multiplication table
;SIZE is the size of the multiplication table to make
Line 3,999 ⟶ 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</
{{out}}
Line 4,018 ⟶ 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">/**
Multiplication table, in Neko
Tectonics:
Line 4,061 ⟶ 5,690:
$print("\n");
j += 1;
}</
{{out}}
Line 4,084 ⟶ 5,713:
=={{header|Nim}}==
{{trans|C}}
<
const n = 12
Line 4,095 ⟶ 5,724:
for j in 1..n:
stdout.write if j<i: " " else: "{:3d} ".fmt(i*j)
echo "| {:2d}".fmt(i)</
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 10 11 12
Line 4,115 ⟶ 5,744:
{{trans|C}}
<
let max = 12 in
let fmax = float_of_int max in
Line 4,133 ⟶ 5,762:
print_newline()
done;
print_newline()</
=={{header|PARI/GP}}==
Quick and dirty one-liner:
<
=={{header|Pascal}}==
Line 4,143 ⟶ 5,772:
=={{header|Perl}}==
<
our $width = length($max**2) + 1;
Line 4,152 ⟶ 5,781:
foreach "$i|", map { $_ >= $i and $_*$i } 1..$max;
print "\n";
}</
{{out}}
Line 4,174 ⟶ 5,803:
=={{header|Phix}}==
{{Trans|Ada}}
<!--<syntaxhighlight lang="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>
<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;">"%4d"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">col</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<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;">"\n--+-"</span><span style="color: #0000FF;">&</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">'-'</span><span style="color: #0000FF;">,</span><span style="color: #000000;">12</span><span style="color: #0000FF;">*</span><span style="color: #000000;">4</span><span style="color: #0000FF;">))</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">row</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>
<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;">"\n%2d| "</span><span style="color: #0000FF;">,</span><span style="color: #000000;">row</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>
<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: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">col</span><span style="color: #0000FF;"><</span><span style="color: #000000;">row</span><span style="color: #0000FF;">?</span><span style="color: #008000;">" "</span><span style="color: #0000FF;">:</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%4d"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">row</span><span style="color: #0000FF;">*</span><span style="color: #000000;">col</span><span style="color: #0000FF;">)))</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</syntaxhighlight>-->
{{out}}
<pre style="font-size: 8px">
Line 4,202 ⟶ 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}}==
<syntaxhighlight lang="picat">go =>
N=12,
make_table(N),
nl.
%
% Make a table of size N
%
make_table(N) =>
printf(" "),
foreach(I in 1..N) printf("%4w", I) end,
nl,
println(['-' : _ in 1..(N+1)*4+1]),
foreach(I in 1..N)
printf("%2d | ", I),
foreach(J in 1..N)
if J>=I then
printf("%4w", I*J)
else
printf(" ")
end
end,
nl
end,
nl.</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|PicoLisp}}==
<
(space 4)
(for X N
Line 4,217 ⟶ 5,924:
(prinl) ) )
(mulTable 12)</
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 10 11 12
Line 4,235 ⟶ 5,942:
=={{header|PL/I}}==
<syntaxhighlight lang="pl/i">
/* 12 x 12 multiplication table. */
Line 4,250 ⟶ 5,957:
end multiplication_table;
</syntaxhighlight>
Result:
<
1 2 3 4 5 6 7 8 9 10 11 12
_________________________________________________
Line 4,269 ⟶ 5,976:
11 | 121 132
12 | 144
</
=={{header|PowerShell}}==
<
$Tab = "`t"
Line 4,292 ⟶ 5,999:
# Combine them all together
) -join $Tab
}</
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 10 11 12
Line 4,308 ⟶ 6,015:
12 144</pre>
<b>A more general solution</b>
<
{
# For clarity
Line 4,333 ⟶ 6,040:
}
Get-TimesTable 18</
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Line 4,356 ⟶ 6,063:
=={{header|Prolog}}==
<
print_header(S,E),
make_table_rows(S,E),
Line 4,388 ⟶ 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).</
{{out}}
<pre>
Line 4,410 ⟶ 6,117:
?-</pre>
=={{header|Python}}==
===Procedural===
<
>>> width = len(str(size**2))
>>> for row in range(-1,size+1):
Line 4,480 ⟶ 6,148:
11│ 121 132
12│ 144
>>> </
The above works with Python 3.X, which uses Unicode strings by default. <br>
Line 4,492 ⟶ 6,160:
and then again, for comparison, as an equivalent '''list monad''' expression (''mulTable2'' function):
<
1. by list comprehension (mulTable ),
Line 4,594 ⟶ 6,262:
if __name__ == '__main__':
main()</
{{Out}}
<pre>By list comprehension (mulTable):
Line 4,630 ⟶ 6,298:
{{Trans|Haskell}}
{{Works with|Python|3.7}}
<
import collections
Line 4,896 ⟶ 6,564:
# MAIN ---
if __name__ == '__main__':
main()</
{{Out}}
<pre> 13 14 15 16 17 18 19 20
Line 4,932 ⟶ 6,600:
99 9801 9900
100 10000</pre>
=={{header|Quackery}}==
<syntaxhighlight lang="quackery"> [ swap number$
tuck size -
times sp echo$ ] is echo-rj ( n n --> )
say " * |"
12 times [ i^ 1+ 4 echo-rj ] cr
say " ---+"
char - 48 of echo$ cr
[ 12 times
[ i^ 1+
dup 3 echo-rj
say " |"
12 times
[ i^ 1+
2dup > iff
[ drop 4 times sp ]
else
[ dip dup
* 4 echo-rj ] ]
cr drop ] ]</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|R}}==
<syntaxhighlight lang="r">
multiplication_table <- function(n=12)
{
Line 4,945 ⟶ 6,654:
}
multiplication_table()
</syntaxhighlight>
=={{header|Racket}}==
<syntaxhighlight lang="racket">
#lang racket
Line 4,960 ⟶ 6,669:
(show-line (cons y (for/list ([x (in-range 1 13)])
(if (<= y x) (* x y) "")))))
</syntaxhighlight>
{{out}}
Line 4,981 ⟶ 6,690:
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" line>(my $f = "%{$_}s" given my $width = ($_**2).chars ) given my $max = 12;
say '×'.fmt($f) ~ ' ┃ ' ~ (1..$max).fmt($f);
say '━' x $width ~ '━╋' ~ '━' x $max × (1+$width);
for 1..$max -> $i {
say $i.fmt($f)
}</syntaxhighlight>
{{out}}
<pre>
Line 5,018 ⟶ 6,717:
=={{header|REBOL}}==
<
Title: "12x12 Multiplication Table"
URL: http://rosettacode.org/wiki/Print_a_Multiplication_Table
Line 5,050 ⟶ 6,749:
print rejoin [ crlf "How about " size: 20 "?" crlf ]
-- .row " x " 1 -- repeat y size [.row p3 y y] --</
{{out}} (only 12x12 shown):
Line 5,072 ⟶ 6,771:
=={{header|REXX}}==
<syntaxhighlight lang="rexx">/*REXX program displays a NxN multiplication table (in a boxed grid) to the terminal.*/
parse arg sz . /*obtain optional argument from the CL.*/
w= max(3, length(sz**2) ); __= copies('─', w) /*calculate the width of the table cell*/
do r=1 for sz
if r==1 then
call bot
exit 0
/*──────────────────────────────────────────────────────────────────────────────────────*/
hdr: $= ?'│'; do i=1 for sz; $=$ || right(i"x|", w+3); end; say $; call sep; return
dap: $= left($, length($) - 1)arg(1);
top: $= '┌'__"┬"copies(___'┬', sz); call dap "┐"; ?= arg(1); say $; call hdr; return
sep: $= '├'__"┼"copies(___'┼', sz); call dap
bot: $= '└'__"┴"copies(___'┴', sz); call dap "┘"; say $; return</syntaxhighlight>
{{out|output|text= when using the default input of: <tt> 12 </tt>}}
<pre>
┌───┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│4x │
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│5x │
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│6x │
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│7x │
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│8x │
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│9x │
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
└───┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
</pre>
{{out|output|text= when using the input of: <tt> 16 </tt>}}
<pre>
┌───┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│4x │
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│5x │
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│6x │
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│9x │
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
└───┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
</pre>
=={{header|Ring}}==
<
multiplication_table(12)
func multiplication_table n
Line 5,206 ⟶ 6,877:
next
func fsize x,n return string(x) + copy(" ",n-len(string(x)))
</syntaxhighlight>
Output
<
| 1 2 3 4 5 6 7 8 9 10 11 12
----+-------------------------------------------------
Line 5,224 ⟶ 6,895:
11 | 121 132
12 | 144
</syntaxhighlight>
=={{header|Ruby}}==
<
puts " |" + (" %3d" * n) % [*1..n]
puts "----+" + "----" * n
Line 5,238 ⟶ 6,909:
end
multiplication_table 12</
{{out}}
Line 5,257 ⟶ 6,928:
12 | 144
</pre>
=={{header|Rust}}==
<
fn main() {
Line 5,293 ⟶ 6,950:
println!("| {}", i);
}
}</
or, in terms of map:
<
let xs = (1..=12)
.map(|a| {
Line 5,313 ⟶ 6,970:
println!("{}", xs.join("\n"))
}</
=={{header|Scala}}==
<
//Multiplication Table
print("%5s".format("|"))
Line 5,335 ⟶ 6,992:
println("")
}
</syntaxhighlight>
=== case ===
<
implicit def intToString(i: Int) = i.toString
val cell = (x:String) => print("%5s".format(x))
Line 5,357 ⟶ 7,014:
}
}
</syntaxhighlight>
=={{header|Scheme}}==
Line 5,363 ⟶ 7,020:
A better implementation of <tt>iota</tt> is provided by SRFI-1 [http://srfi.schemers.org/srfi-1/srfi-1.html].
<
(define iota
(lambda (count start step)
Line 5,390 ⟶ 7,047:
(loop (+ count 1)
(cdr numbers)))))))
</syntaxhighlight>
<pre>
Line 5,410 ⟶ 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 5,431 ⟶ 7,088:
end
printf("%s\n",s)
end</
{{out}}
<pre> | 1 2 3 4 5 6 7 8 9 10 11 12
Line 5,449 ⟶ 7,106:
=={{header|Seed7}}==
<
const proc: main is func
Line 5,472 ⟶ 7,129:
writeln("|" <& i lpad 3);
end for;
end func;</
{{out}}
Line 5,493 ⟶ 7,150:
=={{header|Sidef}}==
<
var width = (max**2 -> len+1)
Line 5,505 ⟶ 7,162:
{ |i|
say fmt_row("#{i}┃", {|j| i <= j ? i*j : ''}.map(1..max)...)
} << 1..max</
{{out}}
<pre>
Line 5,526 ⟶ 7,183:
=={{header|Simula}}==
{{trans|ALGOL W}}
<
integer i, j;
outtext( " " );
Line 5,542 ⟶ 7,199:
outimage
end;
end</
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 10 11 12
Line 5,558 ⟶ 7,215:
11| 121 132
12| 144</pre>
=={{header|Swift}}==
<syntaxhighlight lang="swift">import Foundation
let size = 12
func printRow(with:Int, upto:Int) {
print(String(repeating: " ", count: (with-1)*4), terminator: "")
for i in with...upto {
print(String(format: "%l4d", i*with), terminator: "")
}
print()
}
print(" ", terminator: ""); printRow( with: 1, upto: size)
print( String(repeating: "–", count: (size+1)*4 ))
for i in 1...size {
print(String(format: "%l4d",i), terminator:"")
printRow( with: i, upto: size)
}
</syntaxhighlight>
=={{header|Tailspin}}==
<
templates formatN&{width:}
[ 1..$width -> ' ', '$;'... ] -> '$(last-$width+1..last)...;' !
Line 5,572 ⟶ 7,252:
'$ -> formatN&{width:2};|$:1..($-1)*4 -> ' ';$:$..12 -> $*$row -> formatN&{width:4};
' ! \) -> !OUT::write
</syntaxhighlight>
{{out}}
<pre>
Line 5,592 ⟶ 7,272:
=={{header|Tcl}}==
<
puts \u0020\u2500\u2500\u253c[string repeat \u2500 48]
for {set i 1} {$i <= 12} {incr i} {
Line 5,602 ⟶ 7,282:
}
puts ""
}</
{{out}}
<pre>
Line 5,622 ⟶ 7,302:
=={{header|TUSCRIPT}}==
<
$$ MODE TUSCRIPT
x=y="1'2'3'4'5'6'7'8'9'10'11'12"
Line 5,641 ⟶ 7,321:
PRINT col,cnt
ENDLOOP
</syntaxhighlight>
{{out}}
<pre style='height:30ex;overflow:scroll'>
Line 5,658 ⟶ 7,338:
</pre>
== {{header|
{{trans|
<syntaxhighlight lang="javascript">
// Multiplication tables
var n = 12;
console.clear();
for (j = 1; j < n; j++)
process.stdout.write(j.toString().padStart(3, ' ') + " ");
console.log(n.toString().padStart(3, ' '));
console.log("----".repeat(n) + "+");
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++)
process.stdout.write(j < i ?
" " : (i * j).toString().padStart(3, ' ') + " ");
console.log("| " + i.toString().padStart(2, ' '));
}
</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|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">
#import std
#import nat
Line 5,699 ⟶ 7,390:
main = table 12
</syntaxhighlight>
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 5,719 ⟶ 7,410:
</pre>
=={{header|
<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
End Function
Sub print(s):
On Error Resume Next
WScript.stdout.Write (s)
If err= &h80070006& Then WScript.Echo " Please run this script with CScript": WScript.quit
End Sub
For i=1 To 12
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>
________________________________________________
</pre>
</small>
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<
var nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
Line 5,820 ⟶ 7,460:
var nums2 = nums.map { |n| (n >= i) ? (n * i).toString : " " }.toList
Fmt.print("$3d | $4s", i, nums2)
}</
{{out}}
Line 5,838 ⟶ 7,478:
11 | 121 132
12 | 144
</pre>
=={{header|XPL0}}==
<
int X, Y;
[Format(4, 0);
Line 5,904 ⟶ 7,494:
CrLf(0);
];
]</
{{out}}
Line 5,925 ⟶ 7,515:
=={{header|zkl}}==
<
w,fmt := (n*n).numDigits, " %%%dd".fmt(w).fmt; // eg " %3".fmt
header:=[1..n].apply(fmt).concat(); // 1 2 3 4 ...
Line 5,934 ⟶ 7,524:
[a..n].pump(String,'*(a),fmt).println();
}
}(12);</
{{out}}
<pre>
|