How to resolve the algorithm Multiplication tables step by step in the TypeScript programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Multiplication tables step by step in the TypeScript programming language
Table of Contents
Problem Statement
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.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Multiplication tables step by step in the TypeScript programming language
Source code in the typescript programming language
// Multiplication tables
var n = 12;
console.clear();
for (j = 1; j < n; j++)
process.stdout.write(j.toString().padStart(3, ' ') + " ");
console.log(n.toString().padStart(3, ' '));
console.log("----".repeat(n) + "+");
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++)
process.stdout.write(j < i ?
" " : (i * j).toString().padStart(3, ' ') + " ");
console.log("| " + i.toString().padStart(2, ' '));
}
You may also check:How to resolve the algorithm Multiple distinct objects step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Collections step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm N'th step by step in the MATLAB programming language
You may also check:How to resolve the algorithm Longest increasing subsequence step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Non-decimal radices/Convert step by step in the Common Lisp programming language