Jump to content

Multiplication tables: Difference between revisions

→‎{{header|TypeScript}}: Standard functions have been applied to format numbers.
(→‎{{header|TypeScript}}: Standard functions have been applied to format numbers.)
Line 6,711:
<lang javascript>
// Multiplication tables
 
function intToString(n: number, wdth: number): string {
sn = Math.floor(n).toString();
len = sn.length;
return (wdth < len ? "#".repeat(wdth) : " ".repeat(wdth - len) + sn);
}
 
var n = 12;
console.clear();
for (j = 1; j < n; j++)
process.stdout.write(intToString(j.toString().padStart(3, 3' ') + " ");
console.log(intToString(n.toString().padStart(3, 3' '));
console.log("----".repeat(n) + "+");
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++)
process.stdout.write(j < i ? " " : intToString(i * j, 3) + " ");
" " : (i * j).toString().padStart(3, ' ') + " ");
console.log("| " + intToString(i.toString().padStart(2, 2' '));
}
</lang>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.