How to resolve the algorithm Multiplication tables step by step in the MOO programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Multiplication tables step by step in the MOO 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 MOO programming language
Source code in the moo programming language
@verb me:@tables none none none rxd
@program me:@tables
player:tell(" | 1 2 3 4 5 6 7 8 9 10 11 12");
player:tell("-------------------------------------------------------------------");
for i in [1..12]
line = ((i < 10) ? " " | " ") + tostr(i) + " | ";
for j in [1..12]
if (j >= i)
product = i * j;
"calculate spacing for right justification of values";
if (product >= 100)
spacer = "";
elseif (product >= 10)
spacer = " ";
else
spacer = " ";
endif
line = line + " " + spacer + tostr(product);
else
line = line + " ";
endif
endfor
player:tell(line);
endfor
.
@program me:@tables
player:tell(" | 1 2 3 4 5 6 7 8 9 10 11 12");
player:tell($string_utils:space(67, "-"));
for i in [1..12]
line = " " + $string_utils:right(i, 2) + " | ";
for j in [1..12]
line = line + " " + ((i > j) ? " " | $string_utils:right(j*i, 3));
endfor
player:tell(line);
endfor
.
You may also check:How to resolve the algorithm Unbias a random generator step by step in the CoffeeScript programming language
You may also check:How to resolve the algorithm Interactive programming (repl) step by step in the Java programming language
You may also check:How to resolve the algorithm Walk a directory/Recursively step by step in the GUISS programming language
You may also check:How to resolve the algorithm 99 bottles of beer step by step in the C++ programming language
You may also check:How to resolve the algorithm 99 bottles of beer step by step in the JavaScript programming language