0
0
CsharpProgramBeginner · 2 min read

C# Program to Print Multiplication Table

You can print a multiplication table in C# using a for loop like this: for (int i = 1; i <= 10; i++) { Console.WriteLine($"{number} x {i} = {number * i}"); } where number is the base number for the table.
📋

Examples

Inputnumber = 2
Output2 x 1 = 2 2 x 2 = 4 2 x 3 = 6 2 x 4 = 8 2 x 5 = 10 2 x 6 = 12 2 x 7 = 14 2 x 8 = 16 2 x 9 = 18 2 x 10 = 20
Inputnumber = 5
Output5 x 1 = 5 5 x 2 = 10 5 x 3 = 15 5 x 4 = 20 5 x 5 = 25 5 x 6 = 30 5 x 7 = 35 5 x 8 = 40 5 x 9 = 45 5 x 10 = 50
Inputnumber = 0
Output0 x 1 = 0 0 x 2 = 0 0 x 3 = 0 0 x 4 = 0 0 x 5 = 0 0 x 6 = 0 0 x 7 = 0 0 x 8 = 0 0 x 9 = 0 0 x 10 = 0
🧠

How to Think About It

To print a multiplication table, think of counting from 1 to 10 and multiplying each count by the chosen number. For each step, you show the multiplication expression and its result. This repeats until you reach 10.
📐

Algorithm

1
Get the number for which to print the multiplication table
2
Start a loop from 1 to 10
3
Multiply the number by the current loop count
4
Print the multiplication expression and result
5
Repeat until the loop reaches 10
💻

Code

csharp
using System;
class Program {
    static void Main() {
        int number = 7;
        for (int i = 1; i <= 10; i++) {
            Console.WriteLine($"{number} x {i} = {number * i}");
        }
    }
}
Output
7 x 1 = 7 7 x 2 = 14 7 x 3 = 21 7 x 4 = 28 7 x 5 = 35 7 x 6 = 42 7 x 7 = 49 7 x 8 = 56 7 x 9 = 63 7 x 10 = 70
🔍

Dry Run

Let's trace the multiplication table for number 3 through the code

1

Set number

number = 3

2

Start loop

i = 1

3

Calculate and print

3 x 1 = 3

4

Increment loop

i = 2

5

Calculate and print

3 x 2 = 6

iOutput
13 x 1 = 3
23 x 2 = 6
33 x 3 = 9
43 x 4 = 12
53 x 5 = 15
63 x 6 = 18
73 x 7 = 21
83 x 8 = 24
93 x 9 = 27
103 x 10 = 30
💡

Why This Works

Step 1: Loop from 1 to 10

The for loop runs 10 times, once for each multiplier from 1 to 10.

Step 2: Multiply and print

Inside the loop, the program multiplies the base number by the current loop index and prints the result.

Step 3: Use string interpolation

The $"{number} x {i} = {number * i}" syntax creates a readable output showing the multiplication expression and result.

🔄

Alternative Approaches

Using while loop
csharp
using System;
class Program {
    static void Main() {
        int number = 4;
        int i = 1;
        while (i <= 10) {
            Console.WriteLine($"{number} x {i} = {number * i}");
            i++;
        }
    }
}
This uses a <code>while</code> loop instead of <code>for</code>, which is more flexible but slightly longer.
User input for number
csharp
using System;
class Program {
    static void Main() {
        Console.Write("Enter a number: ");
        int number = int.Parse(Console.ReadLine());
        for (int i = 1; i <= 10; i++) {
            Console.WriteLine($"{number} x {i} = {number * i}");
        }
    }
}
This version asks the user to enter the number, making the program interactive.

Complexity: O(1) time, O(1) space

Time Complexity

The loop runs exactly 10 times, so the time is constant, O(1), regardless of the input number.

Space Complexity

The program uses a fixed amount of memory for variables and output, so space complexity is O(1).

Which Approach is Fastest?

All approaches run in constant time; differences are mainly in code style and user interaction.

ApproachTimeSpaceBest For
For loopO(1)O(1)Simple, clear fixed-length loops
While loopO(1)O(1)Flexible loop conditions
User inputO(1)O(1)Interactive programs
💡
Use string interpolation with $"..." for clear and easy output formatting.
⚠️
Beginners often forget to update the loop counter, causing infinite loops or no output.