Triangular Multiplication Pattern in C#

Beginner
⏱️ 6 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Nested Loops + Multiplication

What You’ll Learn

How to print a triangular multiplication pattern in C# using nested for loops.

On row i, you will print i values: i*1, i*2, ..., i*i.

⭐ Pattern Output

For rows = 10, the pattern looks like this:

Output
1\n2 4\n3 6 9\n4 8 12 16\n5 10 15 20 25\n6 12 18 24 30 36\n7 14 21 28 35 42 49\n8 16 24 32 40 48 56 64\n9 18 27 36 45 54 63 72 81\n10 20 30 40 50 60 70 80 90 100
1

Complete C# Program

The outer loop chooses the row number. The inner loop prints i * j for j = 1..i.

C#
using System;

namespace MyApp
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, j;

            for (i = 1; i <= 10; i++)
            {
                for (j = 1; j <= i; j++)
                    Console.Write((j * i) + " ");

                Console.WriteLine();
            }
        }
    }
}

🧠 How It Works

1

Choose the number of rows

Here we print 10 rows using for (i = 1; i <= 10; i++).

Setup
2

Outer loop controls the row number

On each row, i is the base multiplier (1, 2, 3, ...).

Row control
3

Inner loop prints the products

for (j = 1; j <= i; j++) prints i*j for each column in that row.

Multiplication
4

Move to the next line

Console.WriteLine() ends the row so the next iteration prints on a new line.

Line break
=

Multiplication triangle

Total printed values are \(1+2+\dots+n = n(n+1)/2\), so time complexity is O(n²) for n rows.

2

Variation — User Input Rows

Let the user choose how many rows to print at runtime.

C#
using System;

namespace MyApp
{
    class Program
    {
        static void Main(string[] args)
        {
            int rows;
            Console.Write("Enter number of rows: ");

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

            for (int i = 1; i <= rows; i++)
            {
                for (int j = 1; j <= i; j++)
                    Console.Write((i * j) + " ");

                Console.WriteLine();
            }
        }
    }
}

💡 Tips for Enhancement

Try These

  • Align columns using fixed-width formatting (e.g., {value,4}) for larger rows
  • Remove the trailing space by building a row string and trimming it
  • Print a full multiplication table by making the inner loop go to rows
  • Right-align the triangle with leading spaces

Avoid

  • Skipping input validation when you accept rows from the user
  • Forgetting Console.WriteLine() after each row
  • Using inconsistent spacing (it makes the pattern hard to read)

Key Takeaways

1

The outer loop selects the row multiplier i.

2

The inner loop prints i*j for j = 1..i.

3

Total printed values are triangular numbers: \(n(n+1)/2\).

4

The approach generalizes to other grid/triangle patterns by changing what you print inside the inner loop.

❓ Frequently Asked Questions

Because the last value on row i is i*i. For i = 5, that is 25.
Change the inner loop to run to rows every time: for (j = 1; j <= rows; j++).
Use fixed-width formatting like Console.Write($"{i*j,4}") so each column takes the same width.
O(n²) for n rows, because the total prints are 1+2+…+n.

Explore More C# Number Patterns!

Multiplication-based patterns are a great bridge between loops and real-world arithmetic.

All Number Patterns →
Did you know?

The total count of printed values after n rows is a triangular number: \(n(n+1)/2\). That’s why this kind of triangle often shows up in nested-loop practice problems.

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