Display Multiplication Table in C#

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 2 Code Examples
for loops

What you’ll learn

  • How a for loop prints times-table rows one by one.
  • How to format rows like n x i = result with string interpolation.
  • Two programs: a fixed table for 5 and a Console input version, plus a live preview.

Overview

A multiplication table is a perfect first loop exercise: the base number stays fixed, the multiplier runs from 1 to 10, and each line is one product. No arrays required — just repeated output.

Classic pattern

for (i = 1; i <= 10; i++) — ten rows.

Live preview

Change the base number and see the table instantly.

Reusable helper

PrintMultiplicationTable(base, last) works for any n.

Prerequisites

Basic for loops, integer multiplication, and Console.WriteLine.

  • You know how a for loop repeats a block a fixed number of times.
  • You can use $"..." string interpolation to build readable output lines.

The idea

For a base number n, row i shows n × i. Print rows for i = 1 through 10 (or any limit you choose).

The loop variable is the multiplier; the product is number * i. That is the entire algorithm.

Row i n × i
Loop i = 1..10
Output one line each

Sample rows for n = 5

5 × 1 = 5, 5 × 2 = 10, … up to 5 × 10 = 50. Each line adds 5 to the previous product when the multiplier increases by 1.

Live preview

Enter a base number and print the 1–10 times table in the browser.

Base number

Default matches example 1 (table of 5).

Live result
Press “Print table”.

Algorithm

Goal: print n × 1 through n × last.

Choose base

Use a fixed literal or read n from the user.

Loop multipliers

For i from 1 to last (often 10), compute n * i.

Print each row

Output n x i = product with WriteLine.

📜 Pseudocode

Pseudocode
function printTable(n, last):
    print header for n
    for i from 1 to last:
        print n, " x ", i, " = ", n * i
1

Table for 5 (reference program)

Fixed base 5, multipliers 1 through 10 — matches the classic school times table and the old reference output.

c#
using System;

class Program
{
    static void PrintMultiplicationTable(int number, int last)
    {
        Console.WriteLine($"Multiplication Table for {number}:");

        for (int i = 1; i <= last; i++)
        {
            Console.WriteLine($"{number} x {i} = {number * i}");
        }
    }

    static void Main()
    {
        PrintMultiplicationTable(5, 10);
    }
}

Explanation

Extracting PrintMultiplicationTable with parameters number and last lets you reuse the same logic for any base — not only 5. The loop body is one multiply and one print.

2

Table for user input

Reads a positive integer from the console with int.TryParse, then prints the 1–10 table for that base.

c#
using System;

class Program
{
    static void PrintMultiplicationTable(int number, int last)
    {
        Console.WriteLine($"Multiplication Table for {number}:");

        for (int i = 1; i <= last; i++)
        {
            Console.WriteLine($"{number} x {i} = {number * i}");
        }
    }

    static void Main()
    {
        Console.Write("Enter a positive integer: ");
        string? input = Console.ReadLine();

        if (!int.TryParse(input, out int n) || n <= 0)
        {
            Console.WriteLine("Please enter a valid positive integer.");
            return;
        }

        PrintMultiplicationTable(n, 10);
    }
}

Explanation

TryParse avoids crashes on bad input. Rejecting n <= 0 matches typical classroom rules; you could allow zero if the assignment says so.

Beyond the basics

Full grid. Nested loops can print a 10×10 table of products (Pythagoras table) — outer loop for rows, inner for columns.

while loop. Replace for with int i = 1; while (i <= last) { ... i++; } for the same behavior.

Interview: state the loop bounds, show one sample row on paper, then write the helper method.

❓ FAQ

It is a list of products like n×1, n×2, ... up to a chosen limit such as 10.
Only the multiplier changes each row, so a loop avoids writing ten nearly identical print statements.
Yes. Change the loop upper bound to 12 or pass a different last value to your helper method.
Yes. A while loop with a counter works the same way — for is just cleaner for a fixed range.
The math still works (e.g. 0×3 = 0), but many beginner exercises expect a positive base — validate input when reading from the console.
Use Console.ReadLine() and int.TryParse to safely convert the user's text to an integer.
Printing k rows is O(k) time and O(1) extra space (excluding output).

🔄 Input / output examples

Base (n)Multiplier (i)Row output
515 x 1 = 5
5105 x 10 = 50
373 x 7 = 21
121212 x 12 = 144 (if last = 12)

Edge cases and pitfalls

Validate input when the base comes from the user.

Input

Non-numeric text

int.TryParse returns false — show a friendly message instead of throwing.

Sign

Zero or negative base

Math works, but many exercises expect positive n only.

Limit

last is zero

The loop prints nothing — valid but usually unintended; document expected range.

Overflow

Very large n

n * i can overflow int for huge values — rare in beginner tasks.

⏱️ Time and space complexity

TaskTimeExtra space
Print k rowsO(k)O(1)

Each iteration does constant work — one multiply and one print.

Summary

  • Pattern: loop i from 1 to last, print n x i = n*i.
  • C#: for loop, $"..." interpolation, optional TryParse for input.
  • Complexity: O(k) time for k rows, O(1) extra space.
Did you know?

A multiplication table for n is the list n×1, n×2, ... up to a limit. A simple for loop prints each row in O(k) time for k lines.

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.

8 people found this page helpful