C++ Multiplication Table Program

Beginner
5 min read
Updated: Oct 2026
2 programs
Live preview

What Is a Multiplication Table?

A multiplication table for a number n lists products n × 1, n × 2, n × 3, … up to a chosen limit (commonly 10).

Remember
For n = 5 (limit 10):
  5 × 1 = 5
  5 × 2 = 10
  5 × 3 = 15
  …
  5 × 10 = 50

Pattern:
  for i from 1 to limit:
      print n × i = (n * i)
nin × i
515
5210
51050

How to Print a Multiplication Table in C++

Four clear steps — a simple for loop does the work.

  1. Choose the number n (hard-coded or from input).
  2. Choose the upper limit (often 10).
  3. Loop i from 1 to that limit.
  4. Print each row as n × i = n * i.
MethodIdeaTimeBest for
Fixed 1–10for (i = 1; i <= 10; i++)O(1) rowsClassic beginner demos
Custom limitLoop to a parameter limitO(limit)Flexible / interview follow-ups

Pseudocode

Pseudocode
function PrintTable(n, limit):
    for i from 1 to limit:
        print n, "×", i, "=", n * i

Cheat Sheet

Keep these facts handy while writing the program.

TopicDetail
Row formulan * i for i = 1..limit
Default limit10 in many textbooks
Loopfor is the clearest choice
Outputcout << n << " × " << i << " = " << (n * i)
Inputcin >> n when asked
Classic check5 × 10 = 50

Live Preview

Enter a number to print its table from 1 to 10.

Whole numbers from −99 to 99. Rows 1 through 10.

Result
5 × 1 = 5
5 × 2 = 10
5 × 3 = 15
5 × 4 = 20
5 × 5 = 25
5 × 6 = 30
5 × 7 = 35
5 × 8 = 40
5 × 9 = 45
5 × 10 = 50

Worked Walkthrough — n = 5, limit 5

Each loop step multiplies n by the current i.

Calculation
i = 1 → 5 × 1 = 5
i = 2 → 5 × 2 = 10
i = 3 → 5 × 3 = 15
i = 4 → 5 × 4 = 20
i = 5 → 5 × 5 = 25

Stop when i exceeds the limit

C++ Programs

Start with the classic 1–10 table. Then use a custom limit when the problem asks for more (or fewer) rows.

Example 1 — Fixed 1–10 Table

Print n × 1 through n × 10 with a simple for loop.

C++
#include <iostream>
using namespace std;

int main()
{
    int n = 5;

    for (int i = 1; i <= 10; i++)
    {
        cout << n << " × " << i << " = " << (n * i) << endl;
    }
    return 0;
}

How It Works

  1. Set n = 5 (or read it with cin later).
  2. i starts at 1 and runs while i <= 10.
  3. Each iteration prints one row using n * i.
  4. i++ moves to the next multiplier.
  5. After i = 10, the loop stops — ten rows printed.

Example 2 — Custom Limit

Accept n and a row count so the table length is flexible.

C++
#include <iostream>
using namespace std;

void printTable(int n, int limit)
{
    if (limit < 1)
    {
        cout << "Limit must be at least 1." << endl;
        return;
    }

    for (int i = 1; i <= limit; i++)
    {
        cout << n << " × " << i << " = " << (n * i) << endl;
    }
}

int main()
{
    printTable(7, 5);
    return 0;
}

How It Works

  1. Pass both the number n and the upper limit.
  2. Reject limit < 1 so the loop has a sensible range.
  3. The same for pattern prints 1..limit rows.
  4. For printTable(7, 5) you get five lines ending at 7 × 5 = 35.
  5. Change the limit without rewriting the loop body.

Edge Cases & Pitfalls

Check these before calling the solution done.

Limit ≤ 0

No rows

Validate the upper bound before looping.

n = 0

All zeros

Every product is 0 — still a valid table.

Off-by-one

Use <= limit

i < 10 stops at 9 and misses the last row.

Input

Check cin

Confirm the read succeeded if you take n from the keyboard.

Time and Space Complexity

ProgramTimeExtra space
Fixed 1–10O(1) (10 rows)O(1)
Custom limitO(limit)O(1)

Work grows with the number of rows printed. No extra arrays are required.

Key Takeaways

  • Pattern: loop i and print n * i.
  • Default: many problems use limit 10.
  • Flexible: pass a custom limit when needed.
  • Test: 5 × 10 = 50 is the last row of the classic table.

One line: for each i from 1 to limit, print n × i = n * i.

Frequently Asked Questions

For a number n, it is the list of products n×1, n×2, n×3, … up to a chosen limit (often 10).
A loop prints every row automatically. Writing each line by hand does not scale when the limit changes.
Beginner programs often print 1 through 10. Interviews may ask for a custom upper limit.
Yes mathematically. Products still work (for example 0×5 = 0, (−3)×4 = −12). Validate only if your problem requires positive n.
Printing k rows takes O(k) time and O(1) extra space.

Next: Natural Number

Check whether an integer is a natural number.

Natural number tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful