Pascal: Displaying A Multiplication Table

program ex16;

var     i, t: integer;

begin
  writeln ('Enter a number for a multiplication table');
  readln (t);
  for i := 1 to 12 do
    writeln (i, ' x ', t, ' = ', i * t);
  readln;
end.

We use a for loop to output a table of 12 results of the form '3 x 6 = 18', etc. Note how we use the counter (i) twice in the output statement, once as the first number in the table (i x 2 = ...) and again in the calculation of the answer (i x 2 = i * 2). Loop counters are often used in this way, it's partly why loops are so common.

Back to questions