Multiplication tables: Difference between revisions

Line 6,705:
11 121 132
12 144
</pre>
 
== {{header|TypeScript}} ==
{{trans|Modula-2}}
<lang javascript>
// Multiplication tables
 
function intToString(n: number, wdth: number): string {
sn = Math.floor(n).toString();
len = sn.length;
return (wdth < len ? "#".repeat(wdth) : " ".repeat(wdth - len) + sn);
}
 
var n = 12;
console.clear();
for (j = 1; j < n; j++)
process.stdout.write(intToString(j, 3) + " ");
console.log(intToString(n, 3));
console.log("----".repeat(n) + "+");
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++)
process.stdout.write(j < i ? " " : intToString(i * j, 3) + " ");
console.log("| " + intToString(i, 2));
}
</lang>
{{out}}
<pre>
1 2 3 4 5 6 7 8 9 10 11 12
------------------------------------------------+
1 2 3 4 5 6 7 8 9 10 11 12 | 1
4 6 8 10 12 14 16 18 20 22 24 | 2
9 12 15 18 21 24 27 30 33 36 | 3
16 20 24 28 32 36 40 44 48 | 4
25 30 35 40 45 50 55 60 | 5
36 42 48 54 60 66 72 | 6
49 56 63 70 77 84 | 7
64 72 80 88 96 | 8
81 90 99 108 | 9
100 110 120 | 10
121 132 | 11
144 | 12
</pre>
 
Anonymous user