AlgoMaster Logo

Multiplication Table of a Number

Last Updated: June 7, 2026

easy
3 min read

Understanding the Problem

A multiplication table lists the products of a number with the integers from 1 to 10. The table of 5 is 5, 10, 15, 20, 25, 30, 35, 40, 45, 50. Return those ten products in order as an array.

The output always has exactly 10 elements: the first is n × 1, the last is n × 10. The size never depends on the value of n.

Key Constraints:

  • n can be negative → A negative n produces a table of negative products. The table of -3 is -3, -6, -9, ..., so the same multiplication logic works without any special handling for the sign.
  • n can be zero → Every product of zero is zero, so the table of 0 is ten zeros. The general formula n × i already returns this, so no separate case is needed.
  • -1000 <= n <= 1000 → The largest product is 1000 × 10 = 10000, which fits comfortably in a 32-bit int. There is no overflow concern.

Approach 1: Loop and Multiply

Intuition

The value at step i is n × i, which maps directly to a loop from 1 to 10.

The one detail to track is the offset between counter and index: the product for n × 1 belongs at index 0, so counter i goes at index i - 1.

Algorithm

  1. Create an array result of length 10.
  2. Loop i from 1 to 10.
  3. Set result[i - 1] to n × i.
  4. After the loop, return result.

Example Walkthrough

Input:

5
n

Starting with i = 1, the product is 5 × 1 = 5, which goes at index 0. At i = 2, the product is 5 × 2 = 10 at index 1. The loop continues through i = 10, where 5 × 10 = 50 lands in the final slot. The array fills up one product at a time:

0
5
1
10
2
15
3
20
4
25
5
30
6
35
7
40
8
45
9
50
result

Code

The multiplication operator does the work here, but multiplication is really repeated addition. Can we build the same table using addition alone?

Approach 2: Repeated Addition

Intuition

Multiplying n by i is the same as adding n to itself i times, so n × 3 equals n + n + n. Keep a running total that starts at 0 and add n once per iteration. After the first addition the total is n, after the second 2n, and so on, so the total already equals n × i when it goes into the array.

This produces the same table as Approach 1 without the * operator.

Algorithm

  1. Create an array result of length 10.
  2. Set a running total sum to 0.
  3. Loop i from 1 to 10.
  4. Add n to sum, so sum now equals n × i.
  5. Store sum at index i - 1.
  6. After the loop, return result.

Example Walkthrough

Input:

5
n

The running total starts at 0. On the first step it becomes 0 + 5 = 5, which equals 5 × 1 and goes at index 0. On the second step it becomes 5 + 5 = 10, matching 5 × 2, stored at index 1. Each step adds another 5, so the total climbs to 50 by the tenth step. The accumulated values form the table:

0
5
1
10
2
15
3
20
4
25
5
30
6
35
7
40
8
45
9
50
result

Code