How to resolve the algorithm Multiplication tables step by step in the Nim programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Multiplication tables step by step in the Nim 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 Nim programming language

Source code in the nim programming language

import strfmt

const n = 12

for j in 1..n:
  stdout.write "{:3d}{:s}".fmt(j, if n-j>0: " " else: "\n")
for j in 0..n:
  stdout.write if n-j>0: "----" else: "+\n"
for i in 1..n:
  for j in 1..n:
    stdout.write if j<i: "    " else: "{:3d} ".fmt(i*j)
  echo "| {:2d}".fmt(i)


  

You may also check:How to resolve the algorithm A+B step by step in the Golo programming language
You may also check:How to resolve the algorithm Fractran step by step in the Delphi programming language
You may also check:How to resolve the algorithm Sorting algorithms/Insertion sort step by step in the Action! programming language
You may also check:How to resolve the algorithm Knight's tour step by step in the Scala programming language
You may also check:How to resolve the algorithm A+B step by step in the Processing programming language