Multiplication tables: Difference between revisions

m
syntax highlighting fixup automation
(Convert <lang> elements to <syntaxhighlight>)
m (syntax highlighting fixup automation)
Line 12:
{{trans|C}}
 
<syntaxhighlight lang="11l">V n = 12
L(j) 1..n
print(‘#3’.format(j), end' ‘ ’)
Line 44:
 
=={{header|360 Assembly}}==
<syntaxhighlight lang="360asm">* 12*12 multiplication table 14/08/2015
MULTTABL CSECT
USING MULTTABL,R12
Line 122:
=={{header|8080 Assembly}}==
 
<syntaxhighlight lang="8080asm"> org 100h
lxi h,output
;;; Make the header
Line 240:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang=AArch64"aarch64 Assemblyassembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program multtable64.s */
Line 410:
 
=={{header|Action!}}==
<syntaxhighlight lang=Action"action!">PROC PrintRight(BYTE num,size)
BYTE i
 
Line 491:
 
=={{header|ActionScript}}==
<syntaxhighlight lang=ActionScript"actionscript">
package {
Line 574:
 
=={{header|Ada}}==
<syntaxhighlight lang=Ada"ada">
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
Line 620:
=={{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
Line 658:
 
<!-- {{does not work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release 1.8.8d.fc9.i386 - missing printf and FORMAT}} -->
<syntaxhighlight lang=Algol68"algol68">main:(
INT max = 12;
INT width = ENTIER(log(max)*2)+1;
Line 698:
 
=={{header|ALGOL W}}==
<syntaxhighlight lang="algolw">begin
% print a school style multiplication table %
i_w := 3; s_w := 0; % set output formating %
Line 732:
=={{header|APL}}==
A simple table is trivial:
<syntaxhighlight lang="apl">(⍳12)∘.×⍳12</syntaxhighlight>
 
But that prints out all the duplicated results across the diagonal:
Line 753:
 
{{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}}
Line 777:
=={{header|AppleScript}}==
===Iteration===
<syntaxhighlight lang=AppleScript"applescript ">set n to 12 -- Size of table.
repeat with x from 0 to n
if x = 0 then set {table, x} to {{return}, -1}
Line 819:
 
{{trans|JavaScript}} (ES5 functional version)
<syntaxhighlight lang=AppleScript"applescript">------------------- MULTIPLICATION TABLE -----------------
 
-- multiplicationTable :: Int -> Int -> String
Line 1,034:
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang=ARM"arm Assemblyassembly">
 
/* ARM assembly Raspberry PI */
Line 1,220:
 
=={{header|Arturo}}==
<syntaxhighlight lang="rebol">mulTable: function [n][
print [" |"] ++ map 1..n => [pad to :string & 3]
print "----+" ++ join map 1..n => "----"
Line 1,252:
=={{header|ASIC}}==
{{trans|Modula-2}}
<syntaxhighlight lang="basic">
REM Multiplication tables
N = 12
Line 1,319:
 
=={{header|AutoHotkey}}==
<syntaxhighlight lang="autohotkey">Gui, -MinimizeBox
Gui, Margin, 0, 0
Gui, Font, s9, Fixedsys
Line 1,373:
 
=={{header|AutoIt}}==
<syntaxhighlight lang=AutoIt"autoit">#AutoIt Version: 3.2.10.0
$tableupto=12
$table=""
Line 1,395:
 
=={{header|AWK}}==
<syntaxhighlight lang=AWK"awk">
BEGIN {
for(i=1;i<=12;i++){
Line 1,423:
=={{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.
<syntaxhighlight lang="axe">Fix 5
ClrDraw
For(I,1,10)
Line 1,460:
 
==={{header|Applesoft BASIC}}===
<syntaxhighlight lang=ApplesoftBasic"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
Line 1,472:
 
==={{header|BASIC256}}===
<syntaxhighlight lang="freebasic">print " X| 1 2 3 4 5 6 7 8 9 10 11 12"
print "---+------------------------------------------------"
 
Line 1,492:
==={{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% * @%) ;
Line 1,516:
==={{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
Line 1,589:
12: : : : : : : : : : : :144</pre>
==={{header|FreeBASIC}}===
<syntaxhighlight lang="freebasic">
' FB 1.05.0 Win64
 
Line 1,674:
{{trans|Modula-2}}
{{works with|PC-BASIC|any}}
<syntaxhighlight lang="qbasic">
10 ' Multiplication Tables
20 LET N% = 12
Line 1,712:
 
==={{header|IS-BASIC}}===
<syntaxhighlight lang=IS"is-BASICbasic">100 PROGRAM "Multipli.bas"
110 TEXT 80
120 PRINT TAB(7);
Line 1,728:
 
==={{header|Liberty BASIC}}===
<syntaxhighlight lang="lb">Print " | 1 2 3 4 5 6 7 8 9 10 11 12"
Print "--+------------------------------------------------------------"
 
Line 1,765:
==={{header|Microsoft Small Basic}}===
{{trans|Modula-2}}
<syntaxhighlight lang="microsoftsmallbasic">
n = 12
For j = 1 To n - 1
Line 1,814:
 
==={{header|PureBasic}}===
<syntaxhighlight lang=PureBasic"purebasic">Procedure PrintMultiplicationTable(maxx, maxy)
sp = Len(Str(maxx*maxy)) + 1
trenner$ = "+"
Line 1,853:
 
==={{header|QBasic}}===
<syntaxhighlight lang="qbasic">CLS
 
'header row
Line 1,899:
 
==={{header|Run BASIC}}===
<syntaxhighlight lang=Runbasic"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>"
Line 1,913:
 
==={{header|True BASIC}}===
<syntaxhighlight lang="qbasic">PRINT " X| 1 2 3 4 5 6 7 8 9 10 11 12"
PRINT "---+------------------------------------------------"
 
Line 1,958:
==={{header|Visual Basic}}===
{{works with|Visual Basic|VB6 Standard}}
<syntaxhighlight lang="vb">Sub Main()
Const nmax = 12, xx = 3
Const x = xx + 1
Line 2,003:
{{trans|Modula-2}}
{{works with|Windows XBasic}}
<syntaxhighlight lang="xbasic">
PROGRAM "multiplicationtables"
VERSION "0.0001"
Line 2,051:
 
==={{header|Yabasic}}===
<syntaxhighlight lang="freebasic">print " X| 1 2 3 4 5 6 7 8 9 10 11 12"
print "---+------------------------------------------------"
 
Line 2,070:
 
=={{header|Batch File}}==
<syntaxhighlight lang="dos">@echo off
setlocal enabledelayedexpansion
 
Line 2,137:
 
=={{header|Befunge}}==
<syntaxhighlight 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_$"+---">:#,_$</syntaxhighlight>
Line 2,161:
<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
Line 2,190:
 
=={{header|Bracmat}}==
<syntaxhighlight lang=Bracmat"bracmat"> ( multiplicationTable
= high i j row row2 matrix padFnc tmp
, celPad leftCelPad padFnc celDashes leftDashes
Line 2,263:
 
=={{header|C}}==
<syntaxhighlight lang="c">#include <stdio.h>
 
int main(void)
Line 2,297:
 
=={{header|C sharp}}==
<syntaxhighlight lang="csharp">using System;
 
namespace multtbl
Line 2,359:
and formats the table columns.
 
<syntaxhighlight lang="cpp">#include <iostream>
#include <iomanip>
#include <cmath> // for log10()
Line 2,470:
=={{header|Chef}}==
 
<syntaxhighlight lang="chef">Multigrain Bread.
 
Prints out a multiplication table.
Line 2,555:
This is more generalized.
Any size can be used and the table will be formatted appropriately.
<syntaxhighlight lang="lisp">(let [size 12
trange (range 1 (inc size))
fmt-width (+ (.length (str (* size size))) 1)
Line 2,587:
 
=={{header|COBOL}}==
<syntaxhighlight lang=COBOL"cobol"> identification division.
program-id. multiplication-table.
 
Line 2,651:
 
=={{header|CoffeeScript}}==
<syntaxhighlight lang="coffeescript">
print_multiplication_tables = (n) ->
width = 4
Line 2,705:
 
=={{header|Common Lisp}}==
<syntaxhighlight lang="lisp">
(do ((m 0 (if (= 12 m) 0 (1+ m)))
(n 0 (if (= 12 m) (1+ n) n)))
Line 2,744:
=={{header|D}}==
{{trans|PicoLisp}}
<syntaxhighlight lang="d">void main() {
import std.stdio, std.array, std.range, std.algorithm;
 
Line 2,770:
 
=={{header|DCL}}==
<syntaxhighlight lang=DCL"dcl">$ max = 12
$ h = f$fao( "!4* " )
$ r = 0
Line 2,817:
=={{header|Delphi}}==
{{trans|DWScript}}
<syntaxhighlight lang="delphi">program MultiplicationTables;
 
{$APPTYPE CONSOLE}
Line 2,849:
 
=={{header|Draco}}==
<syntaxhighlight lang="draco">/* Print N-by-N multiplication table */
proc nonrec multab(byte n) void:
byte i,j;
Line 2,893:
=={{header|DWScript}}==
 
<syntaxhighlight lang="delphi">const size = 12;
var row, col : Integer;
 
Line 2,915:
=={{header|E}}==
 
<syntaxhighlight lang="e"> def size := 12
println(`{|style="border-collapse: collapse; text-align: right;"`)
println(`|`)
Line 3,154:
 
=={{header|EchoLisp}}==
<syntaxhighlight lang="scheme">
(lib 'matrix)
 
Line 3,186:
 
=={{header|Elixir}}==
<syntaxhighlight lang="elixir">defmodule RC do
def multiplication_tables(n) do
IO.write " X |"
Line 3,222:
 
=={{header|Erlang}}==
<syntaxhighlight lang=Erlang"erlang">
-module( multiplication_tables ).
 
Line 3,268:
 
=={{header|Euphoria}}==
<syntaxhighlight lang=Euphoria"euphoria">puts(1," x")
for i = 1 to 12 do
printf(1," %3d",i)
Line 3,312:
 
{{Works with|Office 365 betas 2021}}
<syntaxhighlight lang="lisp">FNOVERHALFCARTESIANPRODUCT
=LAMBDA(f,
LAMBDA(n,
Line 3,332:
and also assuming the following generic bindings in the Name Manager for the WorkBook:
 
<syntaxhighlight lang="lisp">MUL
=LAMBDA(a, LAMBDA(b, a * b))
 
Line 3,758:
=={{header|F Sharp|F#}}==
Translation of C#
<syntaxhighlight lang=FSharp"fsharp">
open System
 
Line 3,798:
 
=={{header|Factor}}==
<syntaxhighlight lang="factor">USING: io kernel math math.parser math.ranges sequences ;
IN: multiplication-table
 
Line 3,834:
 
=={{header|FALSE}}==
<syntaxhighlight lang="false">[$100\>[" "]?$10\>[" "]?." "]p:
[$p;! m: 2[$m;\>][" "1+]# [$13\>][$m;*p;!1+]#%"
"]l:
Line 3,841:
=={{header|Fantom}}==
 
<syntaxhighlight lang="fantom">
class Main
{
Line 3,866:
 
=={{header|Forth}}==
<syntaxhighlight lang="forth">
: multiplication-table
cr 2 spaces 13 2 do i 4 u.r loop
Line 3,880:
=={{header|Fortran}}==
{{works with|Fortran|90 and later}}
<syntaxhighlight lang="fortran">program multtable
implicit none
 
Line 3,904:
 
So instead, write the table by first writing a line to a CHARACTER variable then blanking out the unwanted part.
<syntaxhighlight lang=Fortran"fortran">
Cast forth a twelve times table, suitable for chanting at school.
INTEGER I,J !Steppers.
Line 3,933:
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"fortran">
Cast forth a twelve times table, suitable for chanting at school.
INTEGER I,J !Steppers.
Line 3,965:
 
===VAX FORTRAN===
<syntaxhighlight lang=Fortran"fortran">
PROGRAM TABLES
IMPLICIT NONE
Line 3,992:
</syntaxhighlight>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===
<syntaxhighlight lang=Fortran"fortran"> PROGRAM TABLES
C
C Produce a formatted multiplication table of the kind memorised by rote
Line 4,030:
===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.
<syntaxhighlight lang=Fortran"fortran"> PROGRAM TABLES
C
C Produce a formatted multiplication table of the kind memorised by rote
Line 4,062:
3 CONTINUE
C
END</syntaxhighlight>Inserting the following two lines before the inner DO loop will print the format specifier used to print each row of the table.<syntaxhighlight lang=Fortran"fortran"> WRITE(1,4) (A(J), J = 1,24)
4 FORMAT(1x,24A1)</syntaxhighlight>Running the program produces the following output<syntaxhighlight>
| 1 2 3 4 5 6 7 8 9 10 11 12
Line 4,080:
 
=={{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>
 
Line 4,102:
=={{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()
Line 4,144:
 
=={{header|Go}}==
<syntaxhighlight lang="go">
package main
 
Line 4,176:
=={{header|Groovy}}==
Solution:
<syntaxhighlight lang="groovy">def printMultTable = { size = 12 ->
assert size > 1
Line 4,214:
 
=={{header|Haskell}}==
<syntaxhighlight lang="haskell">import Data.Maybe (fromMaybe, maybe)
 
------------------- MULTIPLICATION TABLE -----------------
Line 4,287:
 
Or, more roughly and directly:
<syntaxhighlight lang="haskell">import Data.List (groupBy)
import Data.Function (on)
import Control.Monad (join)
Line 4,313:
 
=={{header|hexiscript}}==
<syntaxhighlight lang="hexiscript">fun format n l
let n tostr n
while len n < l; let n (" " + n); endwhile
Line 4,334:
 
=={{header|HicEst}}==
<syntaxhighlight lang=HicEst"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 4,344:
=={{header|HolyC}}==
{{trans|C}}
<syntaxhighlight lang="holyc">U8 i, j, n = 12;
for (j = 1; j <= n; j++)
if (j != n)
Line 4,367:
 
=={{header|Icon}} and {{header|Unicon}}==
<syntaxhighlight lang=Icon"icon">procedure main()
lim := 13
wid := 5
Line 4,397:
 
=={{header|J}}==
<syntaxhighlight lang="j"> multtable=: <:/~ * */~
format=: 'b4.0' 8!:2 ]
(('*' ; ,.) ,. ({. ; ])@format@multtable) >:i.12
Line 4,420:
 
=={{header|Java}}==
<syntaxhighlight lang=Java"java">public class MultiplicationTable {
public static void main(String[] args) {
for (int i = 1; i <= 12; i++)
Line 4,462:
===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" >
Line 4,520:
===Functional===
====ES5====
<syntaxhighlight lang=JavaScript"javascript">(function (m, n) {
// [m..n]
Line 4,601:
|}
 
<syntaxhighlight lang=JavaScript"javascript">[["x",1,2,3,4,5,6,7,8,9,10,11,12],
[1,1,2,3,4,5,6,7,8,9,10,11,12],
[2,"",4,6,8,10,12,14,16,18,20,22,24],
Line 4,616:
 
====ES6====
<syntaxhighlight lang=JavaScript"javascript">(() => {
"use strict";
 
Line 4,720:
 
=={{header|Jsish}}==
<syntaxhighlight lang="javascript">/* Multiplication tables, is Jsish */
var m, n, tableSize = 12;
 
Line 4,768:
 
=={{header|Julia}}==
<syntaxhighlight lang=Julia"julia">using Printf
 
println(" X | 1 2 3 4 5 6 7 8 9 10 11 12")
Line 4,800:
 
=={{header|Kotlin}}==
<syntaxhighlight lang="scala">// version 1.0.6
 
fun main(args: Array<String>) {
Line 4,835:
Outputs are visible in http://lambdaway.free.fr/lambdawalks/?view=multiplication_table
 
<syntaxhighlight lang="scheme">
{def format
{lambda {:w :c}
Line 4,879:
 
=={{header|Lasso}}==
<syntaxhighlight lang="lasso">define printTimesTables(max::integer) => {
local(result) = ``
local(padSize) = string(#max*#max)->size + 1
Line 4,927:
=={{header|Logo}}==
{{works with|UCB Logo}}
<syntaxhighlight lang="logo">to mult.table :n
type "| | for [i 2 :n] [type form :i 4 0] (print)
(print)
Line 4,943:
 
=={{header|Lua}}==
<syntaxhighlight lang="lua">io.write( " |" )
for i = 1, 12 do
io.write( string.format( "%#5d", i ) )
Line 4,978:
=={{header|M2000 Interpreter}}==
Using jagged array (arrays of arrays)
<syntaxhighlight lang=M2000"m2000 Interpreterinterpreter">
Module CheckIt {
Dim Base 1, A(12)
Line 5,040:
 
=={{header|Maple}}==
<syntaxhighlight lang="maple">printf(" ");
for i to 12 do
printf("%-3d ", i);
Line 5,077:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang=Mathematica"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
Line 5,095:
timesTable.m: (creates Times Table of N degree)
 
<syntaxhighlight lang=MATLAB"matlab">function table = timesTable(N)
table = [(0:N); (1:N)' triu( kron((1:N),(1:N)') )];
end</syntaxhighlight>
Line 5,101:
A minimally vectorized version of the above code:
 
<syntaxhighlight lang=MATLAB"matlab">function table = timesTable(N)
 
%Generates a column vector with integers from 1 to N
Line 5,141:
 
=={{header|Maxima}}==
<syntaxhighlight lang=Maxima"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, " ")
Line 5,175:
=={{header|Modula-2}}==
{{works with|ADW Modula-2|any (Compile with the linker option ''Console Application'').}}
<syntaxhighlight lang="modula2">
MODULE MultiplicationTables;
 
Line 5,236:
=={{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.
<syntaxhighlight lang="moo">
@verb me:@tables none none none rxd
@program me:@tables
Line 5,265:
 
LambdaMOO string utilities version:
<syntaxhighlight lang="moo">
@program me:@tables
player:tell(" | 1 2 3 4 5 6 7 8 9 10 11 12");
Line 5,298:
 
=={{header|MUMPS}}==
<syntaxhighlight lang=MUMPS"mumps">MULTTABLE(SIZE)
;Print out a multiplication table
;SIZE is the size of the multiplication table to make
Line 5,339:
 
=={{header|Neko}}==
<syntaxhighlight lang=ActionScript"actionscript">/**
Multiplication table, in Neko
Tectonics:
Line 5,403:
=={{header|Nim}}==
{{trans|C}}
<syntaxhighlight lang="nim">import strfmt
 
const n = 12
Line 5,434:
{{trans|C}}
 
<syntaxhighlight lang="ocaml">let () =
let max = 12 in
let fmax = float_of_int max in
Line 5,456:
=={{header|PARI/GP}}==
Quick and dirty one-liner:
<syntaxhighlight lang="parigp">for(y=1,12,printf("%2Ps| ",y);for(x=1,12,print1(if(y>x,"",x*y)"\t"));print)</syntaxhighlight>
 
=={{header|Pascal}}==
Line 5,462:
 
=={{header|Perl}}==
<syntaxhighlight lang="perl">our $max = 12;
our $width = length($max**2) + 1;
 
Line 5,493:
=={{header|Phix}}==
{{Trans|Ada}}
<!--<syntaxhighlight lang=Phix"phix">(phixonline)-->
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" | "</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">col</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">12</span> <span style="color: #008080;">do</span>
Line 5,525:
 
=={{header|Picat}}==
<syntaxhighlight lang=Picat"picat">go =>
N=12,
make_table(N),
Line 5,569:
 
=={{header|PicoLisp}}==
<syntaxhighlight lang=PicoLi"picoli/th">sp>(de mulTable (N)
(space 4)
(for X N
Line 5,600:
 
=={{header|PL/I}}==
<syntaxhighlight lang=PL"pl/Ii">
/* 12 x 12 multiplication table. */
 
Line 5,637:
 
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell"># For clarity
$Tab = "`t"
Line 5,673:
12 144</pre>
<b>A more general solution</b>
<syntaxhighlight lang="powershell">function Get-TimesTable ( [int]$Size )
{
# For clarity
Line 5,721:
 
=={{header|Prolog}}==
<syntaxhighlight lang="prolog">make_table(S,E) :-
print_header(S,E),
make_table_rows(S,E),
Line 5,778:
=={{header|Python}}==
===Procedural===
<syntaxhighlight lang="python">>>> size = 12
>>> width = len(str(size**2))
>>> for row in range(-1,size+1):
Line 5,818:
and then again, for comparison, as an equivalent '''list monad''' expression (''mulTable2'' function):
 
<syntaxhighlight lang="python">'''Multiplication table
 
1. by list comprehension (mulTable ),
Line 5,956:
{{Trans|Haskell}}
{{Works with|Python|3.7}}
<syntaxhighlight lang="python">'''Generalised multiplication tables'''
 
import collections
Line 6,262:
=={{header|Quackery}}==
 
<syntaxhighlight lang=Quackery"quackery"> [ swap number$
tuck size -
times sp echo$ ] is echo-rj ( n n --> )
Line 6,301:
 
=={{header|R}}==
<syntaxhighlight lang="r">
multiplication_table <- function(n=12)
{
Line 6,316:
=={{header|Racket}}==
 
<syntaxhighlight lang=Racket"racket">
#lang racket
 
Line 6,348:
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang=perl6"raku" line>(my $f = "%{$_}s" given my $width = ($_**2).chars ) given my $max = 12;
 
say '×'.fmt($f) ~ ' ┃ ' ~ (1..$max).fmt($f);
Line 6,375:
 
=={{header|REBOL}}==
<syntaxhighlight lang=REBOL"rebol">REBOL [
Title: "12x12 Multiplication Table"
URL: http://rosettacode.org/wiki/Print_a_Multiplication_Table
Line 6,429:
 
=={{header|REXX}}==
<syntaxhighlight lang=REXX"rexx">/*REXX program displays a NxN multiplication table (in a boxed grid) to the terminal.*/
parse arg sz . /*obtain optional argument from the CL.*/
if sz=='' | sz=="," then sz= 12 /*Not specified? Then use the default.*/
Line 6,523:
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">
multiplication_table(12)
func multiplication_table n
Line 6,538:
 
Output
<syntaxhighlight lang="ring">
| 1 2 3 4 5 6 7 8 9 10 11 12
----+-------------------------------------------------
Line 6,556:
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">def multiplication_table(n)
puts " |" + (" %3d" * n) % [*1..n]
puts "----+" + "----" * n
Line 6,588:
 
=={{header|Rust}}==
<syntaxhighlight lang="rust">const LIMIT: i32 = 12;
 
fn main() {
Line 6,612:
or, in terms of map:
 
<syntaxhighlight lang="rust">fn main() {
let xs = (1..=12)
.map(|a| {
Line 6,631:
 
=={{header|Scala}}==
<syntaxhighlight lang="scala">
//Multiplication Table
print("%5s".format("|"))
Line 6,653:
 
=== case ===
<syntaxhighlight lang="scala">
implicit def intToString(i: Int) = i.toString
val cell = (x:String) => print("%5s".format(x))
Line 6,678:
A better implementation of <tt>iota</tt> is provided by SRFI-1 [http://srfi.schemers.org/srfi-1/srfi-1.html].
 
<syntaxhighlight lang="scheme">
(define iota
(lambda (count start step)
Line 6,764:
 
=={{header|Seed7}}==
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
const proc: main is func
Line 6,808:
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">var max = 12
var width = (max**2 -> len+1)
 
Line 6,841:
=={{header|Simula}}==
{{trans|ALGOL W}}
<syntaxhighlight lang="simula">begin
integer i, j;
outtext( " " );
Line 6,875:
 
=={{header|Swift}}==
<syntaxhighlight lang="swift">import Foundation
 
let size = 12
Line 6,898:
 
=={{header|Tailspin}}==
<syntaxhighlight lang="tailspin">
templates formatN&{width:}
[ 1..$width -> ' ', '$;'... ] -> '$(last-$width+1..last)...;' !
Line 6,930:
 
=={{header|Tcl}}==
<syntaxhighlight lang="tcl">puts " x\u2502 1 2 3 4 5 6 7 8 9 10 11 12"
puts \u0020\u2500\u2500\u253c[string repeat \u2500 48]
for {set i 1} {$i <= 12} {incr i} {
Line 6,960:
 
=={{header|TUSCRIPT}}==
<syntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
x=y="1'2'3'4'5'6'7'8'9'10'11'12"
Line 6,998:
== {{header|TypeScript}} ==
{{trans|Modula-2}}
<syntaxhighlight lang="javascript">
// Multiplication tables
 
Line 7,035:
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"ursala">
#import std
#import nat
Line 7,070:
=={{header|VBA}}==
 
<syntaxhighlight lang="vb">
Option Explicit
 
Line 7,118:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascript">import "/fmt" for Fmt
 
var nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
Line 7,148:
 
=={{header|XPL0}}==
<syntaxhighlight lang=XPL0"xpl0">include c:\cxpl\codes;
int X, Y;
[Format(4, 0);
Line 7,182:
 
=={{header|zkl}}==
<syntaxhighlight lang="zkl">fcn multiplicationTable(n){
w,fmt := (n*n).numDigits, " %%%dd".fmt(w).fmt; // eg " %3".fmt
header:=[1..n].apply(fmt).concat(); // 1 2 3 4 ...
10,327

edits