Pascal: Finding Products from Multiplication Lookup Tables

Here is the one-dimensional version:

program multiplication_table;
{$APPTYPE CONSOLE}
var i, myvalue, tablevalue: integer;
mtable:array[1..12] of integer;
response:char;

begin
 repeat
  writeln('Enter an integer to create a multiplication table');
  readln(myvalue);
  for i:= 1 to 12 do
  mtable[i]:=i*myvalue;
  writeln('Enter another integer to find your values multiplied');
  readln(tablevalue);
  writeln(tablevalue, ' * ', myvalue, ' = ', mtable[tablevalue]);
  writeln('Another go? Y/N');
  readln(response);
 until not (response in ['Y','y']);
end.
 

Note how the products are stored in an array and the answer to a multiplication is looked up rather than calculated when requied.

Here is the two-dimensional version:

program Project1;

uses SysUtils;

var mult_table:array[1..12,1..12] of integer;
i,j,first_val, second_val:integer;
c:char;

begin
 for i := 1 to 12 do
  for j := 1 to 12 do
  mult_table[i,j] := i * j;
 repeat
  writeln('Enter first value in multiplication expression');
  readln(first_val);
  writeln('Enter second value in multiplication expression');
  readln(second_val);
  writeln(first_val, ' x ', second_val, ' = ', mult_table[first_val,second_val]);
  writeln('Another? Y/N');
  readln(c);
 until c in['N','n'];
 readln;
end.

Back to questions