Multiplication tables: Difference between revisions

m
m (→‎{{header|Wren}}: Minor tidy)
 
(219 intermediate revisions by 61 users not shown)
Line 1:
{{task|Arithmetic operations}} [[Category:Simple]]
[[Category:Simple]]
Produce a formatted 12×12 multiplication table of the kind memorised by rote when in primary school.
 
;Task:
Produce a formatted   12×12   multiplication table of the kind memorized by rote when in primary (or elementary) school.
 
 
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}}==
<langsyntaxhighlight lang="360asm">* 12*12 multiplication table 14/08/2015
MULTTABL CSECT
USING MULTTABL,R12
Line 64 ⟶ 103:
PORT DC C'--+-------------------------------------------------'
YREGS
END MULTTABL</langsyntaxhighlight>
{{out}}
<pre> | 1 2 3 4 5 6 7 8 9 10 11 12
Line 80 ⟶ 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 */
 
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
.equ MAXI, 12
/*********************************/
/* Initialized data */
/*********************************/
.data
sMessValeur: .fill 11, 1, ' ' // size => 11
szCarriageReturn: .asciz "\n"
sBlanc1: .asciz " "
sBlanc2: .asciz " "
sBlanc3: .asciz " "
/*********************************/
/* UnInitialized data */
/*********************************/
.bss
/*********************************/
/* code section */
/*********************************/
.text
.global main
main: // entry of program
ldr x6,qAdrsBlanc1
ldr x7,qAdrsBlanc2
ldr x8,qAdrsBlanc3
// display first line
mov x4,#0
1: // begin loop
mov x0,x4
ldr x1,qAdrsMessValeur // display value
bl conversion10 // call function
strb wzr,[x1,x0] // final zéro on display value
ldr x0,qAdrsMessValeur
bl affichageMess // display message
cmp x4,#10 // one or two digit in résult
csel x0,x7,x8,ge // display 2 or 3 spaces
bl affichageMess // display message
add x4,x4,1 // increment counter
cmp x4,MAXI
ble 1b // loop
ldr x0,qAdrszCarriageReturn
bl affichageMess // display carriage return
 
mov x5,#1 // line counter
2: // begin loop lines
mov x0,x5 // display column 1 with N° line
ldr x1,qAdrsMessValeur // display value
bl conversion10 // call function
strb wzr,[x1,x0] // final zéro
ldr x0,qAdrsMessValeur
bl affichageMess // display message
cmp x5,#10 // one or two digit in N° line
csel x0,x7,x8,ge // display 2 or 3 spaces
bl affichageMess
mov x4,#1 // counter column
3: // begin loop columns
mul x0,x4,x5 // multiplication
mov x3,x0 // save résult
ldr x1,qAdrsMessValeur // display value
bl conversion10 // call function
strb wzr,[x1,x0]
ldr x0,qAdrsMessValeur
bl affichageMess // display message
cmp x3,100 // 3 digits in résult ?
csel x0,x6,x0,ge // display 1 spaces
bge 4f
cmp x3,10 // 2 digits in result
csel x0,x7,x8,ge // display 2 or 3 spaces
 
4:
bl affichageMess // display message
add x4,x4,1 // increment counter column
cmp x4,x5 // < counter lines
ble 3b // loop
ldr x0,qAdrszCarriageReturn
bl affichageMess // display carriage return
add x5,x5,1 // increment line counter
cmp x5,MAXI // MAXI ?
ble 2b // loop
 
100: // standard end of the program
mov x0,0 // return code
mov x8,EXIT // request to exit program
svc 0 // perform the system call
 
qAdrsMessValeur: .quad sMessValeur
qAdrszCarriageReturn: .quad szCarriageReturn
qAdrsBlanc1: .quad sBlanc1
qAdrsBlanc2: .quad sBlanc2
qAdrsBlanc3: .quad sBlanc3
 
/******************************************************************/
/* Converting a register to a decimal unsigned */
/******************************************************************/
/* x0 contains value and x1 address area */
/* x0 return size of result (no zero final in area) */
/* area size => 11 bytes */
.equ LGZONECAL, 10
conversion10:
stp x1,lr,[sp,-16]! // save registers
stp x2,x3,[sp,-16]! // save registers
stp x4,x5,[sp,-16]! // save registers
mov x3,x1
mov x2,#LGZONECAL
mov x4,10
1: // start loop
mov x5,x0
udiv x0,x5,x4
msub x1,x0,x4,x5 // x5 <- dividende. quotient ->x0 reste -> x1
add x1,x1,48 // digit
strb w1,[x3,x2] // store digit on area
cbz x0,2f // stop if quotient = 0
sub x2,x2,1 // else previous position
b 1b // and loop
// and move digit from left of area
2:
mov x4,0
3:
ldrb w1,[x3,x2]
strb w1,[x3,x4]
add x2,x2,1
add x4,x4,1
cmp x2,LGZONECAL
ble 3b
// and move spaces in end on area
mov x0,x4 // result length
mov x1,' ' // space
4:
strb w1,[x3,x4] // store space in area
add x4,x4,1 // next position
cmp x4,LGZONECAL
ble 4b // loop if x4 <= area size
 
100:
ldp x4,x5,[sp],16 // restaur 2 registers
ldp x2,x3,[sp],16 // restaur 2 registers
ldp x1,lr,[sp],16 // restaur 2 registers
ret // return to address lr x30
/********************************************************/
/* File Include fonctions */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
 
</syntaxhighlight>
{{Output}}
<pre>
0 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
</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">
<lang ActionScript>
package {
Line 162 ⟶ 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 191 ⟶ 600:
end loop;
end Multiplication_Table;
</syntaxhighlight>
</lang>
<pre>
| 1 2 3 4 5 6 7 8 9 10 11 12
Line 208 ⟶ 617:
12| 144
</pre>
 
=={{header|Agena}}==
{{Trans|ALGOL_W}}
<syntaxhighlight lang="agena">scope
# print a school style multiplication table
# NB: print outputs a newline at the end, write and printf do not
write( " " );
for i to 12 do printf( " %3d", i ) od;
printf( "\n +" );
for i to 12 do write( "----" ) od;
for i to 12 do
printf( "\n%3d|", i );
for j to i - 1 do write( " " ) od;
for j from i to 12 do printf( " %3d", i * j ) od;
od;
print()
epocs</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|ALGOL 68}}==
{{works with|ALGOL 68|Standard - no extensions to language used}}
Line 214 ⟶ 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 232 ⟶ 676:
OD;
printf(($gl$, hr))
)</langsyntaxhighlight>
{{out}}
<pre>
Line 254 ⟶ 698:
 
=={{header|ALGOL W}}==
<langsyntaxhighlight lang="algolw">begin
% print a school style multiplication table %
i_w := 3; s_w := 0; % set output formating %
Line 267 ⟶ 711:
end;
 
end.</langsyntaxhighlight>
{{out}}
<pre>
Line 285 ⟶ 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===
<lang AppleScript >set n to 12 -- Size of table.
<syntaxhighlight lang="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}
repeat with y from 0 to n
if y's contents = 0 then
if x > 0 then set row to {f(x)}
if x = -1 then set {row, x} to {{f("x")}, 1}
else
if y ≥ x then set end of row to f(x * y)
if y < x then set end of row to f("")
end if
end repeat
set end of table to row & return
end repeat
return table as string
Line 305 ⟶ 795:
-- Handler/Function for formatting fixed width integer string.
on f(x)
set text item delimiters to ""
return (characters -4 thru -1 of (" " & x)) as string
end f</langsyntaxhighlight>
{{out}}
<pre>"
Line 324 ⟶ 814:
12 144
"</pre>
 
===Functional composition===
As an alternative to iteration, we could also write the top level more declaratively, composing a solution from a set of generic functions.
 
{{trans|JavaScript}} (ES5 functional version)
<syntaxhighlight lang="applescript">------------------- MULTIPLICATION TABLE -----------------
 
-- multiplicationTable :: Int -> Int -> String
on multiplicationTable(lower, upper)
tell ap(my tableText, my mulTable)
|λ|(enumFromTo(lower, upper))
end tell
end multiplicationTable
 
 
-- mulTable :: [Int]-> [[Int]]
on mulTable(axis)
script column
on |λ|(x)
script row
on |λ|(y)
if y < x then
{}
else
{x * y}
end if
end |λ|
end script
{{x} & map(row, axis)}
end |λ|
end script
concatMap(column, axis)
end mulTable
 
 
-- tableText :: [[Int]] -> String
on tableText(axis, rows)
set colWidth to 1 + (length of (|last|(|last|(rows)) as string))
set cell to replicate(colWidth, space)
script tableLine
on |λ|(xys)
script tableCell
on |λ|(int)
(characters (-colWidth) thru -1 of (cell & int)) as string
end |λ|
end script
intercalate(space, map(tableCell, xys))
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]
on concatMap(f, xs)
set lst to {}
set lng to length of xs
tell mReturn(f)
repeat with i from 1 to lng
set lst to (lst & |λ|(item i of xs, i, xs))
end repeat
end tell
return lst
end concatMap
 
 
-- enumFromTo :: Int -> Int -> [Int]
on enumFromTo(m, n)
if m > n then
set d to -1
else
set d to 1
end if
set lst to {}
repeat with i from m to n by d
set end of lst to i
end repeat
return lst
end enumFromTo
 
 
-- foldl :: (a -> b -> a) -> a -> [b] -> a
on foldl(f, startValue, xs)
tell mReturn(f)
set v to startValue
set lng to length of xs
repeat with i from 1 to lng
set v to |λ|(v, item i of xs, i, xs)
end repeat
return v
end tell
end foldl
 
 
-- intercalate :: Text -> [Text] -> Text
on intercalate(strText, lstText)
set {dlm, my text item delimiters} to {my text item delimiters, strText}
set strJoined to lstText as text
set my text item delimiters to dlm
return strJoined
end intercalate
 
 
-- justifyRight :: Int -> Char -> Text -> Text
on justifyRight(n, cFiller, strText)
if n > length of strText then
text -n thru -1 of ((replicate(n, cFiller) as text) & strText)
else
strText
end if
end justifyRight
 
 
-- last :: [a] -> a
on |last|(xs)
item -1 of xs
end |last|
 
 
-- map :: (a -> b) -> [a] -> [b]
on map(f, xs)
tell mReturn(f)
set lng to length of xs
set lst to {}
repeat with i from 1 to lng
set end of lst to |λ|(item i of xs, i, xs)
end repeat
return lst
end tell
end map
 
 
-- Lift 2nd class handler function into 1st class script wrapper
-- mReturn :: Handler -> Script
on mReturn(f)
if class of f is script then
f
else
script
property |λ| : f
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
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
 
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 */
/* program multtable.s */
 
/************************************/
/* Constantes */
/************************************/
.equ STDOUT, 1 @ Linux output console
.equ EXIT, 1 @ Linux syscall
.equ WRITE, 4 @ Linux syscall
.equ MAXI, 12
/*********************************/
/* Initialized data */
/*********************************/
.data
sMessValeur: .fill 11, 1, ' ' @ size => 11
szCarriageReturn: .asciz "\n"
sBlanc1: .asciz " "
sBlanc2: .asciz " "
sBlanc3: .asciz " "
/*********************************/
/* UnInitialized data */
/*********************************/
.bss
/*********************************/
/* code section */
/*********************************/
.text
.global main
main: @ entry of program
push {fp,lr} @ saves 2 registers
@ display first line
mov r4,#0
1: @ begin loop
mov r0,r4
ldr r1,iAdrsMessValeur @ display value
bl conversion10 @ call function
mov r2,#0 @ final zéro
strb r2,[r1,r0] @ on display value
ldr r0,iAdrsMessValeur
bl affichageMess @ display message
cmp r4,#10 @ one or two digit in résult
ldrgt r0,iAdrsBlanc2 @ two display two spaces
ldrle r0,iAdrsBlanc3 @ one display 3 spaces
bl affichageMess @ display message
add r4,#1 @ increment counter
cmp r4,#MAXI
ble 1b @ loop
ldr r0,iAdrszCarriageReturn
bl affichageMess @ display carriage return
 
mov r5,#1 @ line counter
2: @ begin loop lines
mov r0,r5 @ display column 1 with N° line
ldr r1,iAdrsMessValeur @ display value
bl conversion10 @ call function
mov r2,#0 @ final zéro
strb r2,[r1,r0]
ldr r0,iAdrsMessValeur
bl affichageMess @ display message
cmp r5,#10 @ one or two digit in N° line
ldrge r0,iAdrsBlanc2
ldrlt r0,iAdrsBlanc3
bl affichageMess
mov r4,#1 @ counter column
3: @ begin loop columns
mul r0,r4,r5 @ multiplication
mov r3,r0 @ save résult
ldr r1,iAdrsMessValeur @ display value
bl conversion10 @ call function
mov r2,#0
strb r2,[r1,r0]
ldr r0,iAdrsMessValeur
bl affichageMess @ display message
cmp r3,#100 @ 3 digits in résult ?
ldrge r0,iAdrsBlanc1 @ yes, display one space
bge 4f
cmp r3,#10 @ 2 digits in result
ldrge r0,iAdrsBlanc2 @ yes display 2 spaces
ldrlt r0,iAdrsBlanc3 @ no display 3 spaces
4:
bl affichageMess @ display message
add r4,#1 @ increment counter column
cmp r4,r5 @ < counter lines
ble 3b @ loop
ldr r0,iAdrszCarriageReturn
bl affichageMess @ display carriage return
add r5,#1 @ increment line counter
cmp r5,#MAXI @ MAXI ?
ble 2b @ loop
 
100: @ standard end of the program
mov r0, #0 @ return code
pop {fp,lr} @restaur 2 registers
mov r7, #EXIT @ request to exit program
svc #0 @ perform the system call
 
iAdrsMessValeur: .int sMessValeur
iAdrszCarriageReturn: .int szCarriageReturn
iAdrsBlanc1: .int sBlanc1
iAdrsBlanc2: .int sBlanc2
iAdrsBlanc3: .int sBlanc3
/******************************************************************/
/* display text with size calculation */
/******************************************************************/
/* r0 contains the address of the message */
affichageMess:
push {r0,r1,r2,r7,lr} @ save registres
mov r2,#0 @ counter length
1: @ loop length calculation
ldrb r1,[r0,r2] @ read octet start position + index
cmp r1,#0 @ if 0 its over
addne r2,r2,#1 @ else add 1 in the length
bne 1b @ and loop
@ so here r2 contains the length of the message
mov r1,r0 @ address message in r1
mov r0,#STDOUT @ code to write to the standard output Linux
mov r7, #WRITE @ code call system "write"
svc #0 @ call systeme
pop {r0,r1,r2,r7,lr} @ restaur des 2 registres */
bx lr @ return
/******************************************************************/
/* Converting a register to a decimal unsigned */
/******************************************************************/
/* r0 contains value and r1 address area */
/* r0 return size of result (no zero final in area) */
/* area size => 11 bytes */
.equ LGZONECAL, 10
conversion10:
push {r1-r4,lr} @ save registers
mov r3,r1
mov r2,#LGZONECAL
 
1: @ start loop
bl divisionpar10U @unsigned r0 <- dividende. quotient ->r0 reste -> r1
add r1,#48 @ digit
strb r1,[r3,r2] @ store digit on area
cmp r0,#0 @ stop if quotient = 0 */
subne r2,#1 @ else previous position
bne 1b @ and loop
@ and move digit from left of area
mov r4,#0
2:
ldrb r1,[r3,r2]
strb r1,[r3,r4]
add r2,#1
add r4,#1
cmp r2,#LGZONECAL
ble 2b
@ and move spaces in end on area
mov r0,r4 @ result length
mov r1,#' ' @ space
3:
strb r1,[r3,r4] @ store space in area
add r4,#1 @ next position
cmp r4,#LGZONECAL
ble 3b @ loop if r4 <= area size
 
100:
pop {r1-r4,lr} @ restaur registres
bx lr @return
 
/***************************************************/
/* division par 10 unsigned */
/***************************************************/
/* r0 dividende */
/* r0 quotient */
/* r1 remainder */
divisionpar10U:
push {r2,r3,r4, lr}
mov r4,r0 @ save value
mov r3,#0xCCCD @ r3 <- magic_number lower
movt r3,#0xCCCC @ r3 <- magic_number upper
umull r1, r2, r3, r0 @ r1<- Lower32Bits(r1*r0) r2<- Upper32Bits(r1*r0)
mov r0, r2, LSR #3 @ r2 <- r2 >> shift 3
add r2,r0,r0, lsl #2 @ r2 <- r0 * 5
sub r1,r4,r2, lsl #1 @ r1 <- r4 - (r2 * 2) = r4 - (r0 * 10)
pop {r2,r3,r4,lr}
bx lr @ leave function
 
 
 
</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}}==
<langsyntaxhighlight lang="autohotkey">Gui, -MinimizeBox
Gui, Margin, 0, 0
Gui, Font, s9, Fixedsys
Line 361 ⟶ 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 380 ⟶ 1,305:
 
=={{header|AutoIt}}==
<langsyntaxhighlight AutoItlang="autoit">#AutoIt Version: 3.2.10.0
$tableupto=12
$table=""
Line 399 ⟶ 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 411 ⟶ 1,336:
print
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 430 ⟶ 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 447 ⟶ 1,372:
DispGraph
getKeyʳ
Fix 4</langsyntaxhighlight>
 
Approximate output:
Line 464 ⟶ 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 491 ⟶ 1,940:
PRINT o$;
NEXT
NEXT</langsyntaxhighlight>
 
{{out}}
Line 511 ⟶ 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|True BASIC}}===
<syntaxhighlight 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</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}}==
<langsyntaxhighlight lang="dos">@echo off
setlocal enabledelayedexpansion
 
Line 572 ⟶ 2,286:
for /l %%A in (1,1,%numspaces%) do set "space=!space! "
goto :EOF
::/The Functions.</langsyntaxhighlight>
{{Out}}
<pre>
Line 591 ⟶ 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 636 ⟶ 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}}==
<langsyntaxhighlight Bracmatlang="bracmat"> ( multiplicationTable
= high i j row row2 matrix padFnc tmp
, celPad leftCelPad padFnc celDashes leftDashes
Line 693 ⟶ 2,415:
)
& out$(multiplicationTable$12)
& done;</langsyntaxhighlight>
{{out}}
<pre> X| 1 2 3 4 5 6 7 8 9 10 11 12
Line 711 ⟶ 2,433:
 
=={{header|C}}==
<syntaxhighlight lang="c">#include <stdio.h>
<lang c>int main()
 
int main(void)
{
int i, j, n = 12;
for (j = 1; j <= n; j++) printf("%3d%c", j, j -!= n ? ' ' : '\n');
for (j = 0; j <= n; j++) printf(j -!= n ? "----" : "+\n");
 
for (i = 1; i <= n; printf("| %d\n", i++)) {
for (j = 1; j <= n; j++)
printf(j < i ? " " : "%3d ", i * j);
printf("| %d\n", i);
}
return 0;
}</langsyntaxhighlight>
{{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
Line 739 ⟶ 2,465:
121 132 | 11
144 | 12</pre>
 
=={{header|C sharp}}==
<syntaxhighlight lang="csharp">using System;
 
namespace multtbl
{
class Program
{
static void Main(string[] args)
{
Console.Write(" X".PadRight(4));
for (int i = 1; i <= 12; i++)
Console.Write(i.ToString("####").PadLeft(4));
 
Console.WriteLine();
Console.Write(" ___");
 
for (int i = 1; i <= 12; i++)
Console.Write(" ___");
 
Console.WriteLine();
for (int row = 1; row <= 12; row++)
{
Console.Write(row.ToString("###").PadLeft(3).PadRight(4));
for (int col = 1; col <= 12; col++)
{
if (row <= col)
Console.Write((row * col).ToString("###").PadLeft(4));
else
Console.Write("".PadLeft(4));
}
 
Console.WriteLine();
}
 
Console.WriteLine();
Console.ReadLine();
}
}
}
</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|C++}}==
Line 745 ⟶ 2,529:
and formats the table columns.
 
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <iomanip>
#include <cmath> // for log10()
Line 822 ⟶ 2,606:
return 0;
}
</syntaxhighlight>
</lang>
 
{{out}}
Line 852 ⟶ 2,636:
12 144
 
</pre>
 
=={{header|C sharp}}==
<lang csharp>using System;
 
namespace multtbl
{
class Program
{
static void Main(string[] args)
{
Console.Write(" X".PadRight(4));
for (int i = 1; i <= 12; i++)
Console.Write(i.ToString("####").PadLeft(4));
 
Console.WriteLine();
Console.Write(" ___");
 
for (int i = 1; i <= 12; i++)
Console.Write(" ___");
 
Console.WriteLine();
for (int row = 1; row <= 12; row++)
{
Console.Write(row.ToString("###").PadLeft(3).PadRight(4));
for (int col = 1; col <= 12; col++)
{
if (row <= col)
Console.Write((row * col).ToString("###").PadLeft(4));
else
Console.Write("".PadLeft(4));
}
 
Console.WriteLine();
}
 
Console.WriteLine();
Console.ReadLine();
}
}
}
</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|Chef}}==
 
<langsyntaxhighlight lang="chef">Multigrain Bread.
 
Prints out a multiplication table.
Line 978 ⟶ 2,704:
Pour contents of the 2nd mixing bowl into the 2nd baking dish.
 
Serves 2.</langsyntaxhighlight>
 
{{out}}
Line 999 ⟶ 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 1,012 ⟶ 2,738:
(for [j trange] j))))))]
(println s)))
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,028 ⟶ 2,754:
11 121 132
12 144
</pre>
 
=={{header|COBOL}}==
<syntaxhighlight lang="cobol"> identification division.
program-id. multiplication-table.
 
environment division.
configuration section.
repository.
function all intrinsic.
 
data division.
working-storage section.
01 multiplication.
05 rows occurs 12 times.
10 colm occurs 12 times.
15 num pic 999.
77 cand pic 99.
77 ier pic 99.
77 ind pic z9.
77 show pic zz9.
 
procedure division.
sample-main.
perform varying cand from 1 by 1 until cand greater than 12
after ier from 1 by 1 until ier greater than 12
multiply cand by ier giving num(cand, ier)
end-perform
 
perform varying cand from 1 by 1 until cand greater than 12
move cand to ind
display "x " ind "| " with no advancing
perform varying ier from 1 by 1 until ier greater than 12
if ier greater than or equal to cand then
move num(cand, ier) to show
display show with no advancing
if ier equal to 12 then
display "|"
else
display space with no advancing
end-if
else
display " " with no advancing
end-if
end-perform
end-perform
 
goback.
end program multiplication-table.
</syntaxhighlight>
{{out}}
<pre>prompt$ cobc -xj multiplication-table.cob
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|CoffeeScript}}==
<langsyntaxhighlight lang="coffeescript">
print_multiplication_tables = (n) ->
width = 4
Line 1,063 ⟶ 2,853:
print_multiplication_tables 12
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,085 ⟶ 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 1,102 ⟶ 2,892:
(format t "~4,D" (* m n))
(format t " "))))))
</syntaxhighlight>
</lang>
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|D}}==
{{trans|PicoLisp}}
<langsyntaxhighlight lang="d">void main() {
import std.stdio, std.array, std.range, std.algorithm;
 
Line 1,114 ⟶ 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 1,130 ⟶ 2,938:
11 121 132
12 144</pre>
 
=={{header|DCL}}==
<langsyntaxhighlight DCLlang="dcl">$ max = 12
$ h = f$fao( "!4* " )
$ r = 0
Line 1,156 ⟶ 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 1,178 ⟶ 2,987:
=={{header|Delphi}}==
{{trans|DWScript}}
<langsyntaxhighlight lang="delphi">program MultiplicationTables;
 
{$APPTYPE CONSOLE}
Line 1,207 ⟶ 3,016:
Writeln;
end;
end.</langsyntaxhighlight>
 
=={{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}}==
 
<langsyntaxhighlight lang="delphi">const size = 12;
var row, col : Integer;
 
Line 1,229 ⟶ 3,081:
PrintLn('');
end;
</syntaxhighlight>
</lang>
 
=={{header|E}}==
 
<langsyntaxhighlight lang="e"> def size := 12
println(`{|style="border-collapse: collapse; text-align: right;"`)
println(`|`)
Line 1,246 ⟶ 3,098:
}
}
println("|}")</langsyntaxhighlight>
 
Targets MediaWiki markup.
Line 1,435 ⟶ 3,287:
|}
</blockquote>
 
=={{header|EasyLang}}==
 
<syntaxhighlight lang="easylang">
n = 12
numfmt 0 4
write " "
for i = 1 to n
write i
.
print ""
write " "
for i = 1 to n
write "----"
.
print ""
for i = 1 to n
write i
write "|"
for j = 1 to n
if j < i
write " "
else
write i * j
.
.
print ""
.
</syntaxhighlight>
 
=={{header|EchoLisp}}==
<langsyntaxhighlight lang="scheme">
(lib 'matrix)
 
Line 1,450 ⟶ 3,331:
(array-print (build-array 13 13 mtable))
 
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,469 ⟶ 3,350:
 
=={{header|Elixir}}==
<langsyntaxhighlight lang="elixir">defmodule RC do
def multiplication_tables(n) do
IO.write " X |"
Line 1,484 ⟶ 3,365:
end
 
RC.multiplication_tables(12)</langsyntaxhighlight>
 
{{out}}
Line 1,502 ⟶ 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 1,530 ⟶ 3,443:
[io:fwrite("~5B", [Sum]) || {_Y, Sum} <- Uptos],
io:nl().
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,549 ⟶ 3,462:
12 144
</pre>
 
 
=={{header|Euphoria}}==
<langsyntaxhighlight Euphorialang="euphoria">puts(1," x")
for i = 1 to 12 do
printf(1," %3d",i)
Line 1,569 ⟶ 3,481:
end for
puts(1,'\n')
end for</langsyntaxhighlight>
 
{{out}}
Line 1,587 ⟶ 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">
<lang FSharp>
open System
 
Line 1,610 ⟶ 3,974:
 
multTable ()
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,630 ⟶ 3,994:
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: io kernel math math.parser math.ranges sequences ;
IN: multiplication-table
 
Line 1,646 ⟶ 4,010:
" +" write
12 [ "----" write ] times nl
1 12 [a,b] [ print-row ] each ;</langsyntaxhighlight>
 
<pre>
Line 1,666 ⟶ 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 1,695 ⟶ 4,059:
}
}
</syntaxhighlight>
</lang>
 
=={{header|Forth}}==
<langsyntaxhighlight lang="forth">
: multiplication-table
cr 2 spaces 13 2 do i 4 u.r loop
Line 1,708 ⟶ 4,072:
loop
loop ;
</syntaxhighlight>
</lang>
 
=={{header|Fortran}}==
{{works with|Fortran|90 and later}}
<langsyntaxhighlight lang="fortran">program multtable
implicit none
 
Line 1,730 ⟶ 4,094:
end do
 
end program multtable</langsyntaxhighlight>
 
===Traditional approach===
The usual style is to write whole lines at a go, traditionally to fast lineprinters. Producing a tabular layout is easy (four characters per field to allow room to print 144 with a space separator), the difficulty lies in having blank parts at the start of the line followed by results. Having results followed by blanks is normal. The simplest way to achieve this would be to have a CHARACTER*4 function IFMT4(n) that returns four spaces for n <= 0, otherwise the digits, similar to the above example. But the plan is to write a line of such function calls at a go (with n = 0 for unwanted results), and alas, very few Fortran implementations allow recursive use of the formatted I/O system - here one level would be inside the function to produce the result for N > 0, and the other is the original WRITE statement that invokes the function.
 
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 1,748 ⟶ 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 1,765 ⟶ 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 1,776 ⟶ 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 1,790 ⟶ 4,154:
(I3,'|',40X,2I4)
(I3,'|',44X,1I4)
A zero count for spacing (the 0X, due to there being no omitted results on the first line) was possibly a weak point, but if not handled, the fallback position would have been to arrange that instead of 12I4 format, the first would be 1X,I3.
 
Some fortrans offer an extension to FORMAT statements, whereby a variable can appear in place of an integer constant, thus instead of say FORMAT (12I4) there could be FORMAT (<n>I4) for example. Then, during the interpretation of the FORMAT text, the current value of variable ''n'' would be accessed. Note that this is on-the-fly:
READ(in,"(I2,<N>I4)") N,(A(I),I = 1,N)
would read N as a two-digit integer, and, as the READ statement executes further, use that value of N both in the FORMAT text's interpretation and in the further processing of the READ statement.
 
===VAX FORTRAN===
<syntaxhighlight lang="fortran">
<lang Fortran>
PROGRAM TABLES
IMPLICIT NONE
Line 1,821 ⟶ 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 1,857 ⟶ 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 1,893 ⟶ 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 1,908 ⟶ 4,273:
10| 100 110 120
11| 121 132
12| 144</langpre>
 
=={{header|Frink}}==
<syntaxhighlight lang="frink">a = makeArray[[13,13], {|a,b| a==0 ? b : (b==0 ? a : (a<=b ? a*b : ""))}]
formatTable[a,"right"]</syntaxhighlight>
 
{{out}}
<pre>
0 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 1,939 ⟶ 4,325:
fmt.Println("")
}
</syntaxhighlight>
</lang>
 
=={{header|Groovy}}==
Solution:
<langsyntaxhighlight lang="groovy">def printMultTable = { size = 12 ->
assert size > 1
Line 1,961 ⟶ 4,347:
}
 
printMultTable()</langsyntaxhighlight>
 
{{out}}
Line 1,978 ⟶ 4,364:
11| 121 132
12| 144</pre>
 
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import ControlData.MonadMaybe (fromMaybe, maybe)
import Text.Printf
 
------------------- MULTIPLICATION TABLE -----------------
main = do
 
putStrLn $ " x" ++ concatMap fmt [1..12]
mulTable :: [Int] -> [[Maybe Int]]
zipWithM_ f [1..12] $ iterate (" " ++) ""
mulTable xs =
where f n s = putStrLn $ fmt n ++ s ++ concatMap (fmt . (*n)) [n..12]
(Nothing : labels) :
fmt n = printf "%4d" (n :: Int)</lang>
zipWith
(:)
labels
[[upperMul x y | y <- xs] | x <- xs]
where
labels = Just <$> xs
upperMul x y
| x > y = Nothing
| otherwise = Just (x * y)
 
 
--------------------------- TEST -------------------------
main :: IO ()
main =
putStrLn . unlines $
showTable . mulTable
<$> [ [13 .. 20],
[1 .. 12],
[95 .. 100]
]
 
------------------------ FORMATTING ----------------------
showTable :: [[Maybe Int]] -> String
showTable xs = unlines $ head rows : [] : tail rows
where
w = succ $ (length . show) (fromMaybe 0 $ (last . last) xs)
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
 
13 169 182 195 208 221 234 247 260
14 196 210 224 238 252 266 280
15 225 240 255 270 285 300
16 256 272 288 304 320
17 289 306 323 340
18 324 342 360
19 361 380
20 400
 
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
 
95 96 97 98 99 100
 
95 9025 9120 9215 9310 9405 9500
96 9216 9312 9408 9504 9600
97 9409 9506 9603 9700
98 9604 9702 9800
99 9801 9900
100 10000</pre>
 
Or, more roughly and directly:
<syntaxhighlight lang="haskell">import Data.List (groupBy)
import Data.Function (on)
import Control.Monad (join)
 
main :: IO ()
main =
mapM_ print $
fmap (uncurry (*)) <$>
groupBy
(on (==) fst)
(filter (uncurry (>=)) $ join ((<*>) . fmap (,)) [1 .. 12])</syntaxhighlight>
{{Out}}
<pre>[1]
[2,4]
[3,6,9]
[4,8,12,16]
[5,10,15,20,25]
[6,12,18,24,30,36]
[7,14,21,28,35,42,49]
[8,16,24,32,40,48,56,64]
[9,18,27,36,45,54,63,72,81]
[10,20,30,40,50,60,70,80,90,100]
[11,22,33,44,55,66,77,88,99,110,121]
[12,24,36,48,60,72,84,96,108,120,132,144]</pre>
 
=={{header|hexiscript}}==
<syntaxhighlight lang="hexiscript">fun format n l
let n tostr n
while len n < l; let n (" " + n); endwhile
return n
endfun
 
print " |"
for let i 1; i <= 12; i++; print format i 4; endfor
print "\n --+"
for let i 1; i <= 12; i++; print "----"; endfor
println ""
for let i 1; i <= 12; i++
print format i 3 + "|"
for let j 1; j <= 12; j++
if j < i; print " "
else print format (i * j) 4; endif
endfor
println ""
endfor</syntaxhighlight>
 
=={{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 1,996 ⟶ 4,493:
WRITE(Row=line+2, Column=4*col, Format='i3') line*col
ENDDO
ENDDO</langsyntaxhighlight>
 
=={{header|HolyC}}==
{{trans|C}}
<syntaxhighlight lang="holyc">U8 i, j, n = 12;
for (j = 1; j <= n; j++)
if (j != n)
Print("%3d%c", j, ' ');
else
Print("%3d%c", j, '\n');
 
for (j = 0; j <= n; j++)
if (j != n)
Print("----");
else
Print("+\n");
 
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++)
if (j < i)
Print(" ");
else
Print("%3d ", i * j);
Print("| %d\n", i);
}</syntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
<langsyntaxhighlight Iconlang="icon">procedure main()
lim := 13
wid := 5
Line 2,005 ⟶ 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 2,027 ⟶ 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 2,047 ⟶ 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}}==
<syntaxhighlight lang="java">public class MultiplicationTable {
<lang Java>
public static void main(String[] args) {
public class MulTable{
for (int i = 1; i <= 12; i++)
public static void main(String args[]){
int System.out.print("\t" + i,j);
for(i=1;i<=12;i++)
{
System.out.print("\t"+i);
}
System.out.println("");
for (int i = 0; i < 100; i++)
System.out.print("-");
System.out.println("");
for (int i = 1; i <= 12; i++) {
System.out.print(""+i + "|");
for(int j = 1; j <= 12; j++) {
ifSystem.out.print(j<i"\t");
if (j >= System.out.print("\t"i);
else System.out.print("\t" + i * j);
System.out.print("\t"+i*j);
}
System.out.println("");
}
}
}</syntaxhighlight>
}
</lang>
{{out}}
<pre>
Line 2,098 ⟶ 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 2,140 ⟶ 4,728:
target.appendChild(table);
}
 
</script>
<style type='text/css'>
Line 2,151 ⟶ 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=====
<syntaxhighlight lang="javascript">(function (m, n) {
 
===Functional (ES5)===
 
<lang JavaScript>(function (m, n) {
// [m..n]
function range(m, n) {
Line 2,172 ⟶ 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 2,206 ⟶ 4,789:
// or simply stringified as JSON
JSON.stringify(lstTable);
})(1, 12);</syntaxhighlight>
})(1, 12);</lang>
 
{{out}}
Line 2,240 ⟶ 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 2,252 ⟶ 4,834:
[10,"","","","","","","","","",100,110,120],
[11,"","","","","","","","","","",121,132],
[12,"","","","","","","","","","","",144]]</langsyntaxhighlight>
 
=====ES6=====
<syntaxhighlight lang="javascript">(() => {
"use strict";
 
// -------------- MULTIPLICATION TABLE ---------------
 
// multTable :: Int -> Int -> [[String]]
const multTable = m => n => {
const xs = enumFromTo(m)(n);
 
return [
["x", ...xs],
...xs.flatMap(
x => [
[x, ...xs.flatMap(
y => y < x ? (
[""]
) : [`${x * y}`]
)]
]
)
];
};
 
// ---------------------- TEST -----------------------
 
// main :: () -> IO String
const main = () =>
wikiTable({
class: "wikitable",
style: [
"text-align:center",
"width:33em",
"height:33em",
"table-layout:fixed"
].join(";")
})(
multTable(1)(12)
);
 
// ---------------- GENERIC FUNCTIONS ----------------
 
// enumFromTo :: Int -> Int -> [Int]
const enumFromTo = m => n =>
n >= m ? Array.from({
length: Math.floor(n - m) + 1
}, (_, 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 `{| ${style}\n${body}\n|}`;
};
 
// MAIN ---
return main();
})();</syntaxhighlight>
{{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}}==
<syntaxhighlight lang="javascript">/* Multiplication tables, is Jsish */
var m, n, tableSize = 12;
 
if (console.args.length > 0) tableSize = parseInt(console.args[0]);
if (tableSize < 1 || tableSize > 20) tableSize = 12;
 
var width = String(tableSize * tableSize).length;
var spaces = ' '.repeat(width+1);
 
printf(spaces);
for (m = 1; m <= tableSize; m++) printf(' %*d', width, m);
printf('\n' + ' '.repeat(width) + '+');
printf('-'.repeat((width+1) * tableSize));
for (m = 1; m <= tableSize; m++) {
printf('\n%*d|', width, m);
for (n = m; n < m; n++) printf(spaces);
for (n = 1; n <= tableSize; n++) {
if (m <= n) printf(' %*d', width, m * n); else printf(spaces);
}
}
printf('\n');</syntaxhighlight>
 
{{out}}
<pre>prompt$ jsish multiplication-tables.jsi
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
 
prompt$ jsish multiplication-tables.jsi 4
1 2 3 4
+------------
1| 1 2 3 4
2| 4 6 8
3| 9 12
4| 16</pre>
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">using Printf
<lang Julia>println(" X | 1 2 3 4 5 6 7 8 9 10 11 12")
 
println(" X | 1 2 3 4 5 6 7 8 9 10 11 12")
println("---+------------------------------------------------")
 
Line 2,266 ⟶ 5,037:
print(" ")
end
end</langsyntaxhighlight>
 
{{out}}
Line 2,283 ⟶ 5,054:
11 | 121 132
12 | 144</pre>
 
=={{header|Kotlin}}==
<syntaxhighlight lang="scala">// version 1.0.6
 
fun main(args: Array<String>) {
print(" x|")
for (i in 1..12) print("%4d".format(i))
println("\n---+${"-".repeat(48)}")
for (i in 1..12) {
print("%3d".format(i) +"|${" ".repeat(4 * i - 4)}")
for (j in i..12) print("%4d".format(i * j))
println()
}
}</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|Lambdatalk]]==
 
Outputs are visible in http://lambdaway.free.fr/lambdawalks/?view=multiplication_table
 
<syntaxhighlight lang="scheme">
{def format
{lambda {:w :c}
{@ style="width::wpx;
color::c;
text-align:right;"
}}}
-> format
 
{def operation
{lambda {:op :i :j}
{if {and {= :i 0} {= :j 0}} // left top cell
then {format 30 #fff} // is empty
else {if {= :i 0} // top row
then {format 30 #ff0}:j // is yellow
else {if {= :j 0} // left col
then {format 30 #0ff}:i // is cyan
else {format 30 #ccc} // is lightgrey
{if {<= :i :j} then {:op :i :j} else .} // cell [i,j]
}}}}}
-> operation
 
{def make_table
{lambda {:func :row :col}
{table {@ style="box-shadow:0 0 8px #000;"}
{S.map // apply
{{lambda {:func :col :j} // function row
{tr {S.map // apply
{{lambda {:func :i :j} // function cell
{td {:func :i :j}}} :func :j} // apply func on [i,j]
{S.serie 0 :col}}}} :func :col} // from 0 to col
{S.serie 0 :row} // from 0 to row
}}}}
-> make_table
 
The following calls:
 
1) {make_table {operation +} 5 15}
2) {make_table {operation *} 12 12}
3) {make_table {operation pow} 6 10}
 
</syntaxhighlight>
 
=={{header|Lasso}}==
<langsyntaxhighlight lang="lasso">define printTimesTables(max::integer) => {
local(result) = ``
local(padSize) = string(#max*#max)->size + 1
Line 2,313 ⟶ 5,163:
}
 
printTimesTables(12)</langsyntaxhighlight>
 
{{out}}
Line 2,330 ⟶ 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>
 
=={{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 2,365 ⟶ 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 2,384 ⟶ 5,216:
end
io.write( "\n" )
end</langsyntaxhighlight>
<pre> | 1 2 3 4 5 6 7 8 9 10 11 12
----------------------------------------------------------------
Line 2,400 ⟶ 5,232:
12 | 144</pre>
 
=={{header|MathematicaM2000 Interpreter}}==
Using jagged array (arrays of arrays)
<lang Mathematica>Grid[{{Range[12]//Column,Grid[UpperTriangularize[KroneckerProduct[Range[12],Range[12]]]/.{0->""}]}}]</lang>
<syntaxhighlight lang="m2000 interpreter">
Module CheckIt {
Dim Base 1, A(12)
Mult=lambda (n)-> {
Flush ' empty stack
For i=1 to n : Data i*n : Next i
=Array([]) ' copy stack in an array, and return a pointer
}
i=Each(A())
Print " |";
while i {
Print Format$("{0:0:-4}",i^+1);
A(i^+1)=Mult(i^+1)
}
Print
Print "--+"+string$("-",4*12)
For i=1 to 12 {
Print Format$("{0:0:-2}|",i);
For j=1 to 12 {
If len(A(j)())>=i then {
Print Format$("{0:0:-4}",A(j)(i-1));
} Else Print " ";
}
Print
}
}
CheckIt
</syntaxhighlight>
 
Final loop can be this, using Each() and r1 as pointer to array.
<pre>
For i=1 to 12 {
j=Each(A())
Print Format$("{0:0:-2}|",i);
While j {
r1=A(j^+1)
If len(r1)>=i then {
Print Format$("{0:0:-4}",Array(r1,i-1));
} Else Print " ";
}
Print
}
</pre>
{{out}}
<pre>
1 | 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|Maple}}==
<syntaxhighlight lang="maple">printf(" ");
for i to 12 do
printf("%-3d ", i);
end do;
printf("\n");
for i to 75 do
printf("-");
end do;
for i to 12 do
printf("\n%2d| ", i);
for j to 12 do
if j<i then
printf(" ");
else
printf("%-3d ", i * j);
end if
end do
end do</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|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">Grid[{{Range[12]//Column,Grid[UpperTriangularize[KroneckerProduct[Range[12],Range[12]]]/.{0->""}]}}]</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
Line 2,415 ⟶ 5,346:
10 100 110 120
11 121 132
12 144</pre>
</pre>
 
=={{header|MATLAB}} / {{header|Octave}}==
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 2,443 ⟶ 5,373:
table = [columnLabels; rowLabels triu(table)];
end</langsyntaxhighlight>
{{out}}
Line 2,467 ⟶ 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
[[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
С/П</langsyntaxhighlight>
 
''Input'': 12 С/П ...
Line 2,498 ⟶ 5,444:
</pre>
 
=={{header|MUMPSModula-2}}==
{{works with|ADW Modula-2|any (Compile with the linker option ''Console Application'').}}
<lang MUMPS>MULTTABLE(SIZE)
<syntaxhighlight lang="modula2">
;Print out a multiplication table
MODULE MultiplicationTables;
;SIZE is the size of the multiplication table to make
;MW is the maximum width of the numbers
;D is the down axis
;A is the across axis
;BAR is the horizontal bar under the operands
NEW MW,D,A,BAR
IF $DATA(SIZE)<1 SET SIZE=12
SET MW=$LENGTH(SIZE*SIZE)
SET BAR="" FOR I=1:1:(MW+2) SET BAR=BAR_"-"
FOR D=1:1:(SIZE+2) DO
.FOR A=1:1:(SIZE+1) DO
..WRITE:(D=1)&(A=1) !,$JUSTIFY("",MW-1)," X|"
..WRITE:(D=1)&(A>1) ?((A-1)*5),$JUSTIFY((A-1),MW)
..WRITE:(D=2)&(A=1) !,BAR
..WRITE:(D=2)&(A'=1) BAR
..WRITE:(D>2)&(A=1) !,$JUSTIFY((D-2),MW)," |"
..WRITE:((A-1)>=(D-2))&((D-2)>=1) ?((A-1)*5),$JUSTIFY((D-2)*(A-1),MW)
KILL MW,D,A,BAR
QUIT</lang>
 
FROM SWholeIO IMPORT
WriteInt;
FROM STextIO IMPORT
WriteString, WriteLn;
 
CONST
N = 12;
 
VAR
I, J: INTEGER;
 
BEGIN
FOR J := 1 TO N - 1 DO
WriteInt(J, 3);
WriteString(" ");
END;
WriteInt(N, 3);
WriteLn;
FOR J := 0 TO N - 1 DO
WriteString("----");
END;
WriteString("+");
WriteLn;
FOR I := 1 TO N DO
FOR J := 1 TO N DO
IF J < I THEN
WriteString(" ");
ELSE
WriteInt(I * J, 3);
WriteString(" ");
END;
END;
WriteString("| ");
WriteInt(I, 2);
WriteLn;
END;
END MultiplicationTables.
</syntaxhighlight>
{{out}}
<pre>
<pre>USER>D MULTTABLE^ROSETTA
1 2 3 4 5 6 7 8 9 10 11 12
------------------------------------------------+
X| 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
-----------------------------------------------------------------
1 | 1 2 3 4 6 5 8 610 12 714 16 818 20 922 24 10| 11 122
2 | 49 12 615 18 821 24 10 27 1230 33 14 36 | 16 18 20 22 243
3 | 16 920 24 12 28 1532 36 18 40 2144 48 24| 27 30 33 364
4 | 25 1630 35 20 40 2445 50 28 55 32 36 40 4460 | 485
5 | 36 42 25 48 3054 60 35 66 4072 | 45 50 55 606
6 | 49 56 3663 70 42 77 48 54 60 6684 | 727
7 | 64 72 80 49 88 56 63 70 7796 | 848
8 | 81 90 99 108 64 72 80 88 | 969
9 | 100 110 120 | 81 90 99 10810
10 | 121 132 | 100 110 12011
11 | 144 | 121 13212
</pre>
12 | 144</pre>
 
=={{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 2,567 ⟶ 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 2,582 ⟶ 5,548:
endfor
.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,600 ⟶ 5,566:
11 | 121 132
12 | 144
</pre>
 
=={{header|MUMPS}}==
<syntaxhighlight lang="mumps">MULTTABLE(SIZE)
;Print out a multiplication table
;SIZE is the size of the multiplication table to make
;MW is the maximum width of the numbers
;D is the down axis
;A is the across axis
;BAR is the horizontal bar under the operands
NEW MW,D,A,BAR
IF $DATA(SIZE)<1 SET SIZE=12
SET MW=$LENGTH(SIZE*SIZE)
SET BAR="" FOR I=1:1:(MW+2) SET BAR=BAR_"-"
FOR D=1:1:(SIZE+2) DO
.FOR A=1:1:(SIZE+1) DO
..WRITE:(D=1)&(A=1) !,$JUSTIFY("",MW-1)," X|"
..WRITE:(D=1)&(A>1) ?((A-1)*5),$JUSTIFY((A-1),MW)
..WRITE:(D=2)&(A=1) !,BAR
..WRITE:(D=2)&(A'=1) BAR
..WRITE:(D>2)&(A=1) !,$JUSTIFY((D-2),MW)," |"
..WRITE:((A-1)>=(D-2))&((D-2)>=1) ?((A-1)*5),$JUSTIFY((D-2)*(A-1),MW)
KILL MW,D,A,BAR
QUIT</syntaxhighlight>
 
{{out}}
<pre>USER>D MULTTABLE^ROSETTA
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|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:
nekoc multiplication-table.neko
neko multiplication-table
*/
 
var sprintf = $loader.loadprim("std@sprintf", 2);
 
var i, j;
 
i = 1;
$print(" X |");
while i < 13 {
$print(sprintf("%4d", i));
i += 1;
}
$print("\n");
$print(" ---+");
i = 1;
while i < 13 {
$print("----");
i += 1;
}
$print("\n");
 
j = 1;
while j < 13 {
$print(sprintf("%3d", j));
$print(" |");
i = 1;
while i < 13 {
if j > i {
$print(" ");
} else {
$print(sprintf("%4d", i*j));
}
i += 1;
}
$print("\n");
j += 1;
}</syntaxhighlight>
 
{{out}}
<pre>prompt$ nekoc multiplication-table.neko
prompt$ neko multiplication-table
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|Nim}}==
{{trans|C}}
<langsyntaxhighlight lang="nim">import strfmt
 
const n = 12
Line 2,615 ⟶ 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 2,635 ⟶ 5,744:
{{trans|C}}
 
<langsyntaxhighlight lang="ocaml">let () =
let max = 12 in
let fmax = float_of_int max in
Line 2,653 ⟶ 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 2,663 ⟶ 5,772:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">our $max = 12;
our $width = length($max**2) + 1;
 
Line 2,672 ⟶ 5,781:
foreach "$i|", map { $_ >= $i and $_*$i } 1..$max;
print "\n";
}</langsyntaxhighlight>
 
{{out}}
Line 2,691 ⟶ 5,800:
12| 144
</pre>
 
=={{header|Perl 6}}==
{{trans|Perl}}
 
{{works with|Rakudo Star|2010.08}}
 
<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), '┃ ', (
for 1..$max -> $j {
$i <= $j ?? $i*$j !! '';
}
).fmt($f);
}</lang>
 
{{out}}
<code>
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
</code>
 
=={{header|Phix}}==
{{Trans|Ada}}
<!--<syntaxhighlight lang="phix">(phixonline)-->
<lang Phix>printf(1," | ")
<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>
for col=1 to 12 do
<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>
printf(1,"%4d",col)
<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>
end for
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
printf(1,"\n--+-"&repeat('-',12*4))
<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>
for row=1 to 12 do
<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>
printf(1,"\n%2d| ",row)
<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>
for col=1 to 12 do
<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>
printf(1,iff(col<row?" ":sprintf("%4d",row*col)))
<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>
end for
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
end for</lang>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</syntaxhighlight>-->
{{out}}
<pre style="font-size: 8px">
Line 2,759 ⟶ 5,833:
12| 144
</pre>
=={{header|PL/I}}==
<lang PL/I>
/* 12 x 12 multiplication table. */
 
=={{header|Phixmonti}}==
multiplication_table: procedure options (main);
<syntaxhighlight lang="Phixmonti">/# Rosetta Code problem: https://rosettacode.org/wiki/Multiplication_tables
declare (i, j) fixed decimal (2);
by Galileo, 11/2022 #/
 
def tab 9 tochar print enddef
put skip edit ((i do i = 1 to 12)) (X(4), 12 F(4));
put skip edit ( (49)'_') (X(3), A);
 
tab 12 for print tab endfor nl
do i = 1 to 12;
tab '-' 12 8 * repeat print nl
put skip edit (i, ' |', (i*j do j = i to 12))
12 for
(F(2), a, col(i*4+1), 12 F(4));
dup print tab 8 tochar print "|" print
end;
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>
end multiplication_table;
</lang>
 
=={{header|Picat}}==
Result:
<syntaxhighlight lang="picat">go =>
N=12,
make_table(N),
nl.
 
%
<lang>
% Make a table of size N
1 2 3 4 5 6 7 8 9 10 11 12
%
_________________________________________________
make_table(N) =>
1 | 1 2 3 4 5 6 7 8 9 10 11 12
printf(" "),
2 | 4 6 8 10 12 14 16 18 20 22 24
foreach(I in 1..N) printf("%4w", I) end,
3 | 9 12 15 18 21 24 27 30 33 36
nl,
4 | 16 20 24 28 32 36 40 44 48
println(['-' : _ in 1..(N+1)*4+1]),
5 | 25 30 35 40 45 50 55 60
foreach(I in 1..N)
6 | 36 42 48 54 60 66 72
printf("%2d | ", I),
7 | 49 56 63 70 77 84
foreach(J in 1..N)
8 | 64 72 80 88 96
if J>=I then
9 | 81 90 99 108
printf("%4w", I*J)
10 | 100 110 120
else
11 | 121 132
printf(" ")
12 | 144
end
</lang>
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}}==
<langsyntaxhighlight PicoLilang="picoli/th">sp>(de mulTable (N)
(space 4)
(for X N
Line 2,810 ⟶ 5,924:
(prinl) ) )
 
(mulTable 12)</langsyntaxhighlight>
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 10 11 12
Line 2,827 ⟶ 5,941:
12 144</pre>
 
=={{header|PureBasicPL/I}}==
<syntaxhighlight lang="pl/i">
<lang PureBasic>Procedure PrintMultiplicationTable(maxx, maxy)
/* 12 x 12 multiplication table. */
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
 
multiplication_table: procedure options (main);
OpenConsole()
declare (i, j) fixed decimal (2);
PrintMultiplicationTable(12, 12)
Input()</lang>
 
put skip edit ((i do i = 1 to 12)) (X(4), 12 F(4));
Ouput similar to ALGOL 68
put skip edit ( (49)'_') (X(3), A);
 
do i = 1 to 12;
put skip edit (i, ' |', (i*j do j = i to 12))
(F(2), a, col(i*4+1), 12 F(4));
end;
 
end multiplication_table;
</syntaxhighlight>
 
Result:
 
<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|PowerShell}}==
<syntaxhighlight lang="powershell"># For clarity
$Tab = "`t"
# Create top row
$Tab + ( 1..12 -join $Tab )
# For each row
ForEach ( $i in 1..12 )
{
$( # The number in the left column
$i
# An empty slot for the bottom triangle
@( "" ) * ( $i - 1 )
# Calculate the top triangle
$i..12 | ForEach { $i * $_ }
# Combine them all together
) -join $Tab
}</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>
<b>A more general solution</b>
<syntaxhighlight lang="powershell">function Get-TimesTable ( [int]$Size )
{
# For clarity
$Tab = "`t"
# Create top row
$Tab + ( 1..$Size -join $Tab )
# For each row
ForEach ( $i in 1..$Size )
{
$( # The number in the left column
$i
# An empty slot for the bottom triangle
@( "" ) * ( $i - 1 )
# Calculate the top triangle
$i..$Size | ForEach { $i * $_ }
# Combine them all together (and send them to the out put stream, which in PowerShell implicityly returns them)
) -join $Tab
}
}
Get-TimesTable 18</syntaxhighlight>
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36
3 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54
4 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72
5 25 30 35 40 45 50 55 60 65 70 75 80 85 90
6 36 42 48 54 60 66 72 78 84 90 96 102 108
7 49 56 63 70 77 84 91 98 105 112 119 126
8 64 72 80 88 96 104 112 120 128 136 144
9 81 90 99 108 117 126 135 144 153 162
10 100 110 120 130 140 150 160 170 180
11 121 132 143 154 165 176 187 198
12 144 156 168 180 192 204 216
13 169 182 195 208 221 234
14 196 210 224 238 252
15 225 240 255 270
16 256 272 288
17 289 306
18 324</pre>
 
=={{header|Prolog}}==
<syntaxhighlight lang="prolog">make_table(S,E) :-
print_header(S,E),
make_table_rows(S,E),
fail.
make_table(_,_).
 
print_header(S,E) :-
nl,
write(' '),
forall(between(S,E,X), print_num(X)),
nl,
Sp is E * 4 + 2,
write(' '),
forall(between(1,Sp,_), write('-')).
make_table_rows(S,E) :-
between(S,E,N),
nl,
print_num(N), write(': '),
between(S,E,N2),
X is N * N2,
print_row_item(N,N2,X).
print_row_item(N, N2, _) :-
N2 < N,
write(' ').
print_row_item(N, N2, X) :-
N2 >= N,
print_num(X).
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).</syntaxhighlight>
{{out}}
<pre>
?- make_table(1,12).
 
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
true.
 
?-</pre>
 
=={{header|Python}}==
===Procedural===
<lang python>>>> size = 12
<syntaxhighlight lang="python">>>> size = 12
>>> width = len(str(size**2))
>>> for row in range(-1,size+1):
Line 2,895 ⟶ 6,148:
11│ 121 132
12│ 144
>>> </langsyntaxhighlight>
 
The above works with Python 3.X, which uses Unicode strings by default. <br>
Declaring a file type of UTF-8 and adding a u to all string literals to transform them into Unicode literals would make the above work in Python 2.X.
<small>(As would using ASCII minus, plus, and pipe characters: "-", "+", "|"; instead of the non-ASCII chars used to draw a frame)</small>.
 
===Functional===
 
We can define a multiplication table string first in terms of a '''list comprehension''' (''mulTable'' function),
 
and then again, for comparison, as an equivalent '''list monad''' expression (''mulTable2'' function):
 
<syntaxhighlight lang="python">'''Multiplication table
 
1. by list comprehension (mulTable ),
2. by list monad. (mulTable2)'''
 
from itertools import chain
 
 
# mulTable :: Int -> String
def mulTable(n):
'''A multiplication table of dimension n,
without redundant entries beneath
the diagonal of squares.'''
 
# colWidth :: Int
colWidth = len(str(n * n))
 
# pad :: String -> String
def pad(s):
return s.rjust(colWidth, ' ')
 
xs = enumFromTo(1)(n)
return unlines([
pad(str(y) + ':') + unwords([
pad(str(x * y) if x >= y else '')
for x in xs
]) for y in xs
])
 
 
# mulTable2 :: Int -> String
def mulTable2(n):
'''Identical to mulTable above,
but the list comprehension is directly
desugared to an equivalent list monad expression.'''
 
# colWidth :: Int
colWidth = len(str(n * n))
 
# pad :: String -> String
def pad(s):
return s.rjust(colWidth, ' ')
 
xs = enumFromTo(1)(n)
return unlines(
bind(xs)(lambda y: [
pad(str(y) + ':') + unwords(
bind(xs)(lambda x: [
pad(str(x * y) if x >= y else '')
])
)
])
)
 
 
# TEST ----------------------------------------------------
# main :: IO ()
def main():
'''Test'''
 
for s, f in [
('list comprehension', mulTable),
('list monad', mulTable2)
]:
print(
'By ' + s + ' (' + f.__name__ + '):\n\n',
f(12).strip() + '\n'
)
 
 
# GENERIC -------------------------------------------------
 
# bind (>>=) :: [a] -> (a -> [b]) -> [b]
def bind(xs):
'''The injection operator for the list monad.
Equivalent to concatMap with its arguments flipped.'''
return lambda f: list(
chain.from_iterable(
map(f, xs)
)
)
 
 
# enumFromTo :: (Int, Int) -> [Int]
def enumFromTo(m):
'''Integer enumeration from m to n.'''
return lambda n: list(range(m, 1 + n))
 
 
# unlines :: [String] -> String
def unlines(xs):
'''A newline-delimited string derived from a list of lines.'''
return '\n'.join(xs)
 
 
# unwords :: [String] -> String
def unwords(xs):
'''A space-delimited string derived from a list of words.'''
return ' '.join(xs)
 
 
if __name__ == '__main__':
main()</syntaxhighlight>
{{Out}}
<pre>By list comprehension (mulTable):
 
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
 
By list monad (mulTable2):
 
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>
 
 
Or, with a little more abstraction, and a complete separation of model from view:
{{Trans|Haskell}}
{{Works with|Python|3.7}}
<syntaxhighlight lang="python">'''Generalised multiplication tables'''
 
import collections
import itertools
import inspect
 
 
# table :: Int -> [[Maybe Int]]
def table(xs):
'''An option-type model of a multiplication table:
a tabulation of Just(x * y) values for all
pairings (x, y) of integers in xs where x > y,
and Nothing values where y <= x.
'''
axis = fmap(Just)(xs)
return list(cons(
cons(Nothing())(axis)
)(zipWith(cons)(axis)([
[
Nothing() if y > x else Just(x * y)
for x in xs
]
for y in xs
])))
 
 
# TEST ----------------------------------------------------
# main :: IO ()
def main():
'''Test'''
print('\n\n'.join(
fmap(fmap(fmap(showTable)(table))(
liftA2(enumFromTo)(fst)(snd)
))(
[(13, 20), (1, 12), (95, 100)]
)
))
 
 
# DISPLAY -------------------------------------------------
 
# showTable :: [[Maybe Int]] -> String
def showTable(xs):
'''A stringification of an abstract model
of a multiplication table.
'''
w = 1 + len(str(last(last(xs))['Just']))
gap = ' ' * w
rows = fmap(fmap(concat)(
fmap(maybe(gap)(
fmap(justifyRight(w)(' '))(str)
))
))(xs)
return unlines([rows[0]] + [''] + rows[1:])
 
 
# GENERIC -------------------------------------------------
 
# Just :: a -> Maybe a
def Just(x):
'''Constructor for an inhabited Maybe (option type) value.'''
return {'type': 'Maybe', 'Nothing': False, 'Just': x}
 
 
# Nothing :: Maybe a
def Nothing():
'''Constructor for an empty Maybe (option type) value.'''
return {'type': 'Maybe', 'Nothing': True}
 
 
# concat :: [[a]] -> [a]
# concat :: [String] -> String
def concat(xs):
'''The concatenation of all the elements
in a list or iterable.'''
chain = itertools.chain
 
def f(ys):
zs = list(chain(*ys))
return ''.join(zs) if isinstance(ys[0], str) else zs
 
return (
f(xs) if isinstance(xs, list) else (
chain.from_iterable(xs)
)
) if xs else []
 
 
# cons :: a -> [a] -> [a]
def cons(x):
'''Construction of a list from x as head,
and xs as tail.'''
chain = itertools.chain
return lambda xs: [x] + xs if (
isinstance(xs, list)
) else chain([x], xs)
 
 
# curry :: ((a, b) -> c) -> a -> b -> c
def curry(f):
'''A curried function derived
from an uncurried function.'''
signature = inspect.signature
if 1 < len(signature(f).parameters):
return lambda x: lambda y: f(x, y)
else:
return f
 
 
# enumFromTo :: (Int, Int) -> [Int]
def enumFromTo(m):
'''Integer enumeration from m to n.'''
return lambda n: list(range(m, 1 + n))
 
 
# fmap :: Functor f => (a -> b) -> f a -> f b
def fmap(f):
'''A function f mapped over a functor.'''
def go(x):
defaultdict = collections.defaultdict
return defaultdict(list, [
('list', fmapList),
# ('iter', fmapNext),
# ('Either', fmapLR),
# ('Maybe', fmapMay),
# ('Tree', fmapTree),
# ('tuple', fmapTuple),
('function', fmapFn),
('type', fmapFn)
])[
typeName(x)
](f)(x)
return lambda v: go(v)
 
 
# fmapFn :: (a -> b) -> (r -> a) -> r -> b
def fmapFn(f):
'''fmap over a function.
The composition of f and g.
'''
return lambda g: lambda x: f(g(x))
 
 
# fmapList :: (a -> b) -> [a] -> [b]
def fmapList(f):
'''fmap over a list.
f lifted to a function over a list.
'''
return lambda xs: list(map(f, xs))
 
 
# fst :: (a, b) -> a
def fst(tpl):
'''First member of a pair.'''
return tpl[0]
 
 
# justifyRight :: Int -> Char -> String -> String
def justifyRight(n):
'''A string padded at left to length n,
using the padding character c.
'''
return lambda c: lambda s: s.rjust(n, c)
 
 
# last :: [a] -> a
def last(xs):
'''The last element of a non-empty list.'''
return xs[-1]
 
 
# liftA2 :: (a -> b -> c) -> f a -> f b -> f c
def liftA2(f):
'''Lift a binary function to the type of a.'''
def go(a, b):
defaultdict = collections.defaultdict
return defaultdict(list, [
# ('list', liftA2List),
# ('Either', liftA2LR),
# ('Maybe', liftA2May),
# ('Tree', liftA2Tree),
# ('tuple', liftA2Tuple),
('function', liftA2Fn)
])[
typeName(a)
](f)(a)(b)
return lambda a: lambda b: go(a, b)
 
 
# liftA2Fn :: (a0 -> b -> c) -> (a -> a0) -> (a -> b) -> a -> c
def liftA2Fn(op):
'''Lift a binary function to a composition
over two other functions.
liftA2 (*) (+ 2) (+ 3) 7 == 90
'''
def go(f, g):
return lambda x: curry(op)(
f(x)
)(g(x))
return lambda f: lambda g: go(f, g)
 
 
# maybe :: b -> (a -> b) -> Maybe a -> b
def maybe(v):
'''Either the default value v, if m is Nothing,
or the application of f to x,
where m is Just(x).
'''
return lambda f: lambda m: v if m.get('Nothing') else (
f(m.get('Just'))
)
 
 
# typeName :: a -> String
def typeName(x):
'''Name string for a built-in or user-defined type.
Selector for type-specific instances
of polymorphic functions.
'''
if isinstance(x, dict):
return x.get('type') if 'type' in x else 'dict'
else:
return 'iter' if hasattr(x, '__next__') else (
type(x).__name__
)
 
 
# snd :: (a, b) -> b
def snd(tpl):
'''Second member of a pair.'''
return tpl[1]
 
 
# uncurry :: (a -> b -> c) -> ((a, b) -> c)
def uncurry(f):
'''A function over a pair of arguments,
derived from a vanilla or curried function.
'''
signature = inspect.signature
if 1 < len(signature(f).parameters):
return lambda xy: f(*xy)
else:
return lambda x, y: f(x)(y)
 
 
# unlines :: [String] -> String
def unlines(xs):
'''A single string derived by the intercalation
of a list of strings with the newline character.
'''
return '\n'.join(xs)
 
 
# zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
def zipWith(f):
'''A list constructed by zipping with a
custom function, rather than with the
default tuple constructor.
'''
return lambda xs: lambda ys: (
map(uncurry(f), xs, ys)
)
 
 
# MAIN ---
if __name__ == '__main__':
main()</syntaxhighlight>
{{Out}}
<pre> 13 14 15 16 17 18 19 20
 
13 169 182 195 208 221 234 247 260
14 196 210 224 238 252 266 280
15 225 240 255 270 285 300
16 256 272 288 304 320
17 289 306 323 340
18 324 342 360
19 361 380
20 400
 
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
 
95 96 97 98 99 100
 
95 9025 9120 9215 9310 9405 9500
96 9216 9312 9408 9504 9600
97 9409 9506 9603 9700
98 9604 9702 9800
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">
<lang r>
multiplication_table <- function(n=12)
{
Line 2,913 ⟶ 6,654:
}
multiplication_table()
</syntaxhighlight>
</lang>
 
=={{header|Racket}}==
 
<syntaxhighlight lang="racket">
<lang Racket>
#lang racket
 
Line 2,928 ⟶ 6,669:
(show-line (cons y (for/list ([x (in-range 1 13)])
(if (<= y x) (* x y) "")))))
</syntaxhighlight>
</lang>
 
{{out}}
Line 2,945 ⟶ 6,686:
11 121 132
12 144
</pre>
 
=={{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) ~ ' ┃ ' ~ ( $i ≤ $_ ?? $i×$_ !! '' for 1..$max ).fmt($f);
}</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|REBOL}}==
<langsyntaxhighlight REBOLlang="rebol">REBOL [
Title: "12x12 Multiplication Table"
Author: oofoe
Date: 2009-12-26
URL: http://rosettacode.org/wiki/Print_a_Multiplication_Table
]
Line 2,982 ⟶ 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 3,004 ⟶ 6,771:
 
=={{header|REXX}}==
<syntaxhighlight lang="rexx">/*REXX program displays a NxN multiplication table (in a boxed grid) to the terminal.*/
A lot of the program code deals with the presentation/display of the multiplication grid.
parse arg sz . /*obtain optional argument from the CL.*/
<lang REXX>/*REXX program displays a NxN multiplication table (in a boxed grid). */
parseif arg high .sz=='' | sz=="," then sz= 12 /*getNot optionalspecified? grid sizeThen fromuse the Cdefault.L. */
w= max(3, length(sz**2) ); __= copies('─', w) /*calculate the width of the table cell*/
if high=='' then high=12 /*Not specified? Then use the default.*/
bar = '│' ; dash ___= __'──' /*(vertical)literals used in the subroutines. bar; horizontal bar (dash)*/
bj do r=1 for sz '┴' ; tj = '┬' /*bottomcalculate and& topformat junctionsa row (orof the tees).table*/
cj if r== '┼' 1 then call top left('│(x)', w+1) /*centershow junctiontitle of (ormultiplication cross)table. */
lj $= ''center(r"x", w)"│" ; rj = '┤' /*leftindex andfor righta junctionsmultiplication table (or tees)row.*/
tlc = '┌' ; do c=1 trcfor sz; = '┐' /*prod= top left and right corners./*build a row of multiplication table. */
blc = '└' ; if r<=c brc then prod= '┘'r /*bottom c " " /*only display " " when the row column. */
$= $ || right(prod, w+1) '|' /*append [↑]product to definea stuffcell toin holdthe boxrow. glyphs*/
cell = cj || copies(dash, 5) end /*define the top of the cell. k*/
say $ /*show a row of multiplication table. */
sep = copies(cell, high+1)rj /*construct the table separator. */
L = length(sep) if r\==sz then call sep /*the length of the /*show a separator except line.for last row.*/
width= length(cell)-1 end /*width of the table cells. j*/
sizecall bot = width-1 /*width forshow the productsbottom inline of the table. */
box.exit 0 = left('', width) /*initializestick alla the cellsfork in theit, we're all done. table*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
 
hdr: $= ?'│'; do i=1 for sz; $=$ || right(i"x|", w+3); end; say $; call sep; return
do j=0 to high /*step through zero ───► high. */
dap: _$=right left(j$, sizelength($) - 1)arg(1)'x; ' /*build the "label" (border) number. */return
top: $= '┌'__"┬"copies(___'┬', sz); call dap "┐"; ?= arg(1); say $; call hdr; return
box.0.j=_ /* " " top label cell. */
sep: box.j.0$=_ '├'__"┼"copies(___'┼', sz); call dap "┤"; say $; /* " " left label cell. */return
bot: $= '└'__"┴"copies(___'┴', sz); call dap "┘"; say $; return</syntaxhighlight>
end /*j*/
{{out|output|text=&nbsp; when using the default input of: &nbsp; &nbsp; <tt> 12 </tt>}}
 
box.0.0=centre('times', width) /*redefie box.0.0 with "times". */
 
do r=1 for high /*step through row one ───► high. */
do c=r to high /*step through column row ───► high. */
box.r.c=right(r*c, size)' ' /*build a single multiplication cell. */
end /*c*/
end /*r*/ /*only build the top right-half of grid*/
 
do r=0 to high; @=sep /*step through all lines; use a mod sep*/
if r==0 then do
@=overlay(tlc,@ , 1) /*use a better tlc (top left corner). */
@=overlay(trc,@ , L) /* " " " trc ( " right " ). */
@=translate(@,tj,cj) /* " " " tj (top junction/tee).*/
end
else @=overlay(lj, @ ,1) /* " " " lj (left junction/tee).*/
say @ /*display a single table grid line. */
if r==0 then call buildLine 00 /* " " " blank grid " */
call buildLine r /*build a single line of the grid. */
if r==0 then call buildLine 00 /*display a single blank grid line. */
end /*r*/
 
@=sep /*allow use of a modified separator. */
@=overlay(blc, @ , 1) /*use a better bottom left corner. */
@=overlay(brc, @ , L) /* " " " " right corner. */
@=translate(@, bj, cj) /* " " " " junction. */
say @ /*display a (single) table grid line. */
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
buildLine: parse arg row,,$ /*start with a blank cell ($). */
do col=0 to high /*step through zero ───► high. */
$=$ || bar || box.row.col /*build one cell at a time. */
end /*col*/
say $ || bar /*finish building the last cell. */
return</lang>
'''output''' &nbsp; when using the default input:
<pre>
┌───┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
(x)1x| 2x| 3x| 4x| 5x| 6x| 7x| 8x| 9x| 10x| 11x| │ │ │ │ │ │12x|
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│times│ 1x │ 2x │ 3x │ 4x │ 5x │ 6x │ 7x │ 8x │ 9x │ 10x │ 11x │ 12x │
│1x1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 │ │ │ │|
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ 1x│2x1 | 2 4 | 3 6 | 4 8 | 510 | 12 6| 14 | 7 16 | 818 | 20 9| 22 10| 24 11 │ 12 │|
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ 2x│3x| 4 | 6 9 | 812 | 1015 | 1218 | 1421 | 1624 | 1827 | 2030 | 2233 | 2436 |
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│4x 3x | | | 9 16 | 12 20 | 15 24 | 18 28 | 21 32 | 24 36 | 27 40 | 30 44 | 33 48 36 │|
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│5x 4x | | | 16| 25 20| 30 24| 35 28| 40 32| 45 36| 50 40| 55 44| 60 48 │|
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│6x 5x | | | | 25| 36 30| 42 35| 48 40| 54 45| 60 50| 66 55| 72 60 │|
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│7x 6x | | | | | 36| 49 42| 56 48| 63 54| 70 60| 77 66| 84 72 │|
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│8x 7x | | | | | | 49| 64 56| 72 63| 80 70| 88 77| 96 84 │|
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│9x 8x | | | | | | | 64| 81 72| 90 80| 99 88| 108 96 │|
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│10x│ 9x | | | | | | | | 81| 100 | 90110 | 120 99 │ 108 │|
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│11x│ 10x | | | | | | | | | 100 110| 121 120| 132 |
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│12x│ 11x | | | | | | | | | | 121 132| 144 |
└───┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ 12x │ │ │ │ │ │ │ │ │ │ │ │ 144 │
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
</pre>
 
'''output''' &nbsp; when the following is used for input: &nbsp; <tt> 16 </tt>
{{out|output|text=&nbsp; when using the input of: &nbsp; &nbsp; <tt> 16 </tt>}}
<pre>
┌───┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
(x)1x| 2x| 3x| 4x| 5x| 6x| 7x| 8x| 9x| 10x| 11x| 12x| 13x| 14x| 15x| │ │ │ │ │ │ │ │16x|
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│times│ 1x │ 2x │ 3x │ 4x │ 5x │ 6x │ 7x │ 8x │ 9x │ 10x │ 11x │ 12x │ 13x │ 14x │ 15x │ 16x │
│1x1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 │ │ │ │ │|
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ 1x│2x1 | 2 4 | 3 6 | 4 8 | 510 | 12 6| 14 | 7 16 | 818 | 20 9| 22 10| 24 11| 26 12| 28 13| 30 14| 32 15 │ 16 │|
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ 2x│3x| 4 | 6 9 | 812 | 1015 | 1218 | 1421 | 1624 | 1827 | 2030 | 2233 | 2436 | 2639 | 2842 | 3045 | 3248 |
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│4x 3x | | | 9 16 | 12 20 | 15 24 | 18 28 | 21 32 | 24 36 | 27 40 | 30 44 | 33 48 | 36 52 | 39 56 | 42 60 | 45 64 48 │|
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│5x 4x | | | 16| 25 20| 30 24| 35 28| 40 32| 45 36| 50 40| 55 44| 60 48| 65 52| 70 56| 75 60| 80 64 │|
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│6x 5x | | | | 25| 36 30| 42 35| 48 40| 54 45| 60 50| 66 55| 72 60| 78 65| 84 70| 90 75| 96 80 │|
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ 6x│7x| | | | | 36 42| 49 48| 56 54| 63 60| 70 66| 77 72| 84 78| 91 84| 98 90| 105 | 96112 |
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ 7x│8x| | | | | | 49 56| 64 63| 72 70| 80 77| 88 84| 96 91| 104 | 98112 | 105120 | 112128 |
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│9x 8x | | | | | | | 64| 81 72| 90 80| 99 88| 108 | 96117 | 104126 | 112135 | 120144 │ 128 │|
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│10x│ 9x | | | | | | | | 81| 100 | 90110 | 120 99| 130 108| 140 117| 150 126| 160 135 │ 144 │|
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│11x│ 10x | | | | | | | | | 100 110| 121 120| 132 130| 143 140| 154 150| 165 160| 176 |
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│12x│ 11x | | | | | | | | | | 121 132| 144 143| 156 154| 168 165| 180 176| 192 |
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│13x│ 12x | | | | | | | | | | | 144 156| 169 168| 182 180| 195 192| 208 |
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│14x│ 13x | | | | | | | | | | | | 169 182| 196 195| 210 208| 224 |
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│15x│ 14x | | | | | | | | | | | | | 196 210| 225 224| 240 |
├───┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│16x│ 15x | | | | | | | | | | | | | | 225 240| 256 |
└───┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ 16x │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ 256 │
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
</pre>
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">
multiplication_table(12)
func multiplication_table n
nSize = 4 See " | "
for t = 1 to n see fsize(t, nSize) next
see nl + "----+-" + copy("-", nSize*n) + nl
for t1 = 1 to n
see fsize(t1, nSize) + "| "
for t2 = 1 to n if t2 >= t1 see fsize(t1*t2,nSize) else see copy(" ", nSize) ok next
see nl
next
func fsize x,n return string(x) + copy(" ",n-len(string(x)))
</syntaxhighlight>
 
Output
<syntaxhighlight lang="ring">
| 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
</syntaxhighlight>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">def multiplication_table(n)
puts " |" + (" %3d" * n) % [*1..n]
puts "----+" + "----" * n
Line 3,147 ⟶ 6,909:
end
 
multiplication_table 12</langsyntaxhighlight>
 
{{out}}
Line 3,166 ⟶ 6,928:
12 | 144
</pre>
 
=={{header|Run BASIC}}==
=={{header|Rust}}==
<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>"
<syntaxhighlight lang="rust">const LIMIT: i32 = 12;
For i = 1 To 12
 
html "<TR align=right><TD>";i;"</td>"
fn main() {
For ii = 1 To 12
for i in 1..LIMIT+1 {
html "<td width=25>"
print!("{:3}{}", i, if LIMIT - i == 0 {'\n'} else {' '})
If ii >= i Then html i * ii
}
html "</td>"
for i in 0..LIMIT+1 {
Next ii
print!("{}", if LIMIT - i == 0 {"+\n"} else {"----"});
next i
}
html "</table>"
 
</lang>Output:
for i in 1..LIMIT+1 {
<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>
for j in 1..LIMIT+1 {
if j < i {
print!(" ")
} else {
print!("{:3} ", j * i)
}
}
println!("| {}", i);
}
}</syntaxhighlight>
 
or, in terms of map:
 
<syntaxhighlight lang="rust">fn main() {
let xs = (1..=12)
.map(|a| {
(1..=12)
.map(|b| {
if a > b {
String::from(" ")
} else {
format!("{:4}", a * b)
}
})
.collect::<String>()
})
.collect::<Vec<String>>();
 
println!("{}", xs.join("\n"))
}</syntaxhighlight>
 
=={{header|Scala}}==
<syntaxhighlight lang="scala">
//Multiplication Table
print("%5s".format("|"))
for (i <- 1 to 12) print("%5d".format(i))
println()
println("-----" * 13)
 
for (i <- 1 to 12) {
print("%4d|".format(i))
 
for (j <- 1 to 12) {
if (i <= j)
print("%5d".format(i * j))
else
print("%5s".format(""))
}
 
println("")
}
</syntaxhighlight>
 
=== case ===
<syntaxhighlight lang="scala">
implicit def intToString(i: Int) = i.toString
val cell = (x:String) => print("%5s".format(x))
 
for {
i <- 1 to 14
j <- 1 to 14
}
yield {
(i, j) match {
case (i, 13) => cell("|")
case (i, 14) if i > 12 => cell("\n")
case (13, j) => cell("-----")
case (i, 14) => cell(i + "\n")
case (14, j) => cell(j)
case (i, j) if i <= j => cell(i*j)
case (i, j) => cell("-")
}
}
</syntaxhighlight>
 
=={{header|Scheme}}==
Line 3,184 ⟶ 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 3,211 ⟶ 7,047:
(loop (+ count 1)
(cdr numbers)))))))
</syntaxhighlight>
</lang>
 
<pre>
Line 3,228 ⟶ 7,064:
144
</pre>
 
=={{header|Rust}}==
<lang rust>const LIMIT: i32 = 12;
 
fn main() {
for i in 1..LIMIT+1 {
print!("{:3}{}", i, if LIMIT - i == 0 {'\n'} else {' '})
}
for i in 0..LIMIT+1 {
print!("{}", if LIMIT - i == 0 {"+\n"} else {"----"});
}
 
for i in 1..LIMIT+1 {
for j in 1..LIMIT+1 {
if j < i {
print!(" ")
} else {
print!("{:3} ", j * i)
}
}
println!("| {}", i);
}
 
 
}</lang>
 
=={{header|Scilab}}==
{{works with|Scilab|5.5.1}}
<syntaxhighlight lang="scilab"> nmax=12, xx=3
s= blanks(xx)+" |"
for j=1:nmax
Line 3,277 ⟶ 7,088:
end
printf("%s\n",s)
end</langsyntaxhighlight>
{{out}}
<pre> | 1 2 3 4 5 6 7 8 9 10 11 12
Line 3,295 ⟶ 7,106:
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
const proc: main is func
Line 3,318 ⟶ 7,129:
writeln("|" <& i lpad 3);
end for;
end func;</langsyntaxhighlight>
 
{{out}}
Line 3,339 ⟶ 7,150:
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">var max = 12;
var width = (max**2 -> len+1);
 
 
func fmt_row(*items) {
items.map { |s| "%*s" % (width, s) }.join('');
}
 
say fmt_row('x┃', (1..max)...)
say "#{'━' * (width - 1)}╋#{'━' * (max * width)}"
 
{ |i| 
say fmt_row('x┃', (1..max)...);
say fmt_row("#{'━'i}┃", *{|j| (widthi -<= 1)}╋#{'━'j ? i*j : ''}.map(1..max * width)}";...)
} << 1..max</syntaxhighlight>
 
max.times { |i|
say fmt_row("#{i}┃", (1..max).map {|j| i <= j ? i*j : ''}...);
};</lang>
{{out}}
<pre>
Line 3,368 ⟶ 7,179:
11┃ 121 132
12┃ 144
</pre>
 
=={{header|Simula}}==
{{trans|ALGOL W}}
<syntaxhighlight lang="simula">begin
integer i, j;
outtext( " " );
for i := 1 step 1 until 12 do outint( i, 4 );
outimage;
outtext( " +" );
for i := 1 step 1 until 12 do outtext( "----" );
outimage;
for i := 1 step 1 until 12 do
begin
outint( i, 3 );
outtext( "|" );
for j := 1 step 1 until i - 1 do outtext( " " );
for j := i step 1 until 12 do outint( i * j, 4 );
outimage
end;
end</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|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}}==
<syntaxhighlight lang="tailspin">
templates formatN&{width:}
[ 1..$width -> ' ', '$;'... ] -> '$(last-$width+1..last)...;' !
end formatN
 
' |$:1..12 -> formatN&{width: 4};
' -> !OUT::write
'--+$:1..12*4 -> '-';
' -> !OUT::write
1..12 -> \( def row: $;
'$ -> formatN&{width:2};|$:1..($-1)*4 -> ' ';$:$..12 -> $*$row -> formatN&{width:4};
' ! \) -> !OUT::write
</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|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 3,381 ⟶ 7,282:
}
puts ""
}</langsyntaxhighlight>
{{out}}
<pre>
Line 3,401 ⟶ 7,302:
 
=={{header|TUSCRIPT}}==
<langsyntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
x=y="1'2'3'4'5'6'7'8'9'10'11'12"
Line 3,420 ⟶ 7,321:
PRINT col,cnt
ENDLOOP
</syntaxhighlight>
</lang>
{{out}}
<pre style='height:30ex;overflow:scroll'>
Line 3,437 ⟶ 7,338:
</pre>
 
== {{header|uBasic/4tHTypeScript}} ==
{{trans|BBC BASICModula-2}}
<syntaxhighlight lang="javascript">
<lang>For R = 1 To 12
// Multiplication tables
Print R;Tab(R * 5);
 
For C = R To 12
var n = 12;
Print Using "_____";R * C;
console.clear();
Next
for (j = 1; j < n; j++)
Print
process.stdout.write(j.toString().padStart(3, ' ') + " ");
Next</lang>
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>
<pre>1 1 2 3 4 5 6 7 8 9 10 11 12
2 1 2 3 4 4 5 6 7 8 8 10 9 12 10 1411 16 18 20 22 2412
------------------------------------------------+
3 9 12 15 18 21 24 27 30 33 36
4 1 2 3 4 5 6 16 20 24 287 328 369 10 40 11 4412 | 481
5 4 6 8 10 12 14 16 18 20 22 25 24 | 30 35 40 45 50 55 602
6 9 12 15 18 21 24 27 30 33 36 | 42 48 54 60 66 723
7 16 20 24 28 32 36 40 44 48 | 49 56 63 70 77 844
8 25 30 35 40 45 50 55 60 | 64 72 80 88 965
9 36 42 48 54 60 66 72 | 81 90 99 1086
10 49 56 63 70 77 84 | 100 110 1207
11 64 72 80 88 96 | 121 1328
12 81 90 99 108 | 1449
100 110 120 | 10
121 132 | 11
144 | 12
</pre>
 
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 3,477 ⟶ 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 3,497 ⟶ 7,410:
</pre>
 
=={{header|Visual BasicVBScript}}==
<syntaxhighlight lang="vb">
{{works with|Visual Basic|VB6 Standard}}
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>Sub Main()
End Function
Const nmax = 12, xx = 3
Sub print(s):
Const x = xx + 1
On Error Resume Next
Dim i As Integer, j As Integer, s As String
WScript.stdout.Write (s)
s = String(xx, " ") & " |"
If err= &h80070006& Then WScript.Echo " Please run this script with CScript": WScript.quit
For j = 1 To nmax
End Sub
s = s & Right(String(x, " ") & j, x)
For i=1 To 12
Next j
print pad(i,-4)
Debug.Print s
Next
s = String(xx, "-") & " +"
print vbCrLf & String(48,"_")
For j = 1 To nmax
For i=1 To 12
s = s & " " & String(xx, "-")
print vbCrLf
Next j
For j=1 Debug.PrintTo s12
if j<i Then print Space(4) Else print pad(i*j,-4)
For i = 1 To nmax
Next
s = Right(String(xx, " ") & i, xx) & " |"
print "|"& pad(i,-2)
For j = 1 To nmax
Next
If j >= i _
</syntaxhighlight>
Then s = s & Right(String(x, " ") & i * j, x) _
{{out}}
Else s = s & String(x, " ")
<small>
Next j
<pre>
Debug.Print s
1 2 3 4 5 6 7 8 9 10 11 12
Next i
________________________________________________
End Sub 'Main</lang>
1 2 3 4 5 6 7 8 9 10 11 12| 1
{{Out}}
4 6 8 10 12 14 16 18 20 22 24| 2
<pre">
| 1 2 9 312 15 4 18 521 24 6 27 730 33 8 36| 9 10 11 123
16 20 24 28 32 36 40 44 48| 4
--- + --- --- --- --- --- --- --- --- --- --- --- ---
1 | 1 2 3 4 525 30 6 35 740 45 8 50 955 1060| 11 125
2 | 4 6 8 10 12 1436 1642 1848 2054 2260 2466 72| 6
3 | 9 12 15 18 21 24 2749 3056 3363 3670 77 84| 7
4 | 16 20 24 28 32 36 40 64 44 72 80 88 96| 488
5 | 25 30 35 40 45 50 55 81 90 99 108| 609
6 | 36 42 48 54 60 66 72100 110 120|10
7 | 49 56 63 70 77 84 121 132|11
8 | 64 72 80 88 96 144|12
</pre>
9 | 81 90 99 108
</small>
10 | 100 110 120
=={{header|Wren}}==
11 | 121 132
{{libheader|Wren-fmt}}
12 | 144
<syntaxhighlight lang="wren">import "./fmt" for Fmt
 
var nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
Fmt.print(" x | $4d", nums)
System.print("----+%("-" * 60)")
for (i in 1..12) {
var nums2 = nums.map { |n| (n >= i) ? (n * i).toString : " " }.toList
Fmt.print("$3d | $4s", i, nums2)
}</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|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">include c:\cxpl\codes;
int X, Y;
[Format(4, 0);
Line 3,555 ⟶ 7,494:
CrLf(0);
];
]</langsyntaxhighlight>
 
{{out}}
Line 3,576 ⟶ 7,515:
 
=={{header|zkl}}==
<syntaxhighlight lang="zkl">fcn multiplicationTable(n){
<lang zkl>println(" x 1 2 3 4 5 6 7 8 9 10 11 12\n"
w,fmt := (n*n).numDigits, " %%%dd".fmt(w).fmt; // eg " %3".fmt
" -----------------------------------------------");
header:=[1..n].apply(fmt).concat(); // 1 2 3 4 ...
foreach a in ([1..12]){
printprintln("%2d| x ".fmt(a), header, "\n - ", "-"*header.len(a-1));
[a..12].pump(dash:=String,'*(a),"%3d ".fmt).println(*w,"-"); // eg " -"
foreach a in ([1..n]){
}</lang>
print("%2d|".fmt(a),dash*(a-1));
[a..n].pump(String,'*(a),fmt).println();
}
}(12);</syntaxhighlight>
{{out}}
<pre>
9,488

edits