C# Multiplication Number Triangle Pattern

Beginner
5 min read
Updated: Sep 2026
3 programs
Live preview

What Is This Pattern?

A triangular multiplication pattern prints the products i × 1, i × 2, …, i × i on row i.

Remember
Rule: on row i, print i*j for j = 1..i

1
2 4
3 6 9
4 8 12 16
5 10 15 20 25   ← rows = 5

In C# the outer loop sets the row multiplier i; the inner loop runs j from 1 to i and prints i * j.

How to Solve It

One nested loop: row multiplier outside, column factors inside.

MethodIdeaBest for
Product trianglePrint i * j for j = 1..iLearning, interviews, exams
Fixed widthSame products with {0,3} columnsNeater console output

Pseudocode

Pseudocode
for i from 1 to rows:
    for j from 1 to i:
        print i * j and a space
    print newline

Cheat sheet

GoalPattern
Walk rowsfor (i = 1; i <= rows; i++)
Walk columnsfor (j = 1; j <= i; j++)
Print productConsole.Write((i * j) + " ");
Aligned columnsConsole.Write("{0,3}", i * j);
End the rowConsole.WriteLine();

Write vs WriteLine

APIEffectUse for
Console.WriteStays on the same lineEach product (plus space or width)
Console.WriteLineEnds the current lineAfter the inner loop finishes a row

Live Preview

Change the row count and the multiplication triangle updates instantly.

Whole numbers from 1 to 10. Tap a chip or type a value — the preview redraws as you go.

Live result 5 rows · 15 products
1 
2 4 
3 6 9 
4 8 12 16 
5 10 15 20 25 

Worked Walkthrough — rows = 4

Trace each row’s products from i*1 through i*i.

iProducts i*jPrinted row
111
22, 42 4
33, 6, 93 6 9
44, 8, 12, 164 8 12 16

Total products for n rows = n(n+1)/2. Last value on row i is always i*i.

C# Programs

Three complete programs: fixed 5 rows, user-input rows, and fixed-width columns. Use View Output for sample results.

Example 1 — Fixed rows = 5

Nested loops print i * j with a trailing space.

C#
using System;

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

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

                Console.WriteLine();
            }
        }
    }
}

How It Works

1. Outer loop. i is the row multiplier — row 3 uses 3 as the base.

2. Inner loop. j runs from 1 to i; each cell prints i * j.

3. New line. WriteLine after the inner loop starts the next row.

Example 2 — User Input (rows)

Read the row count and build the same triangle.

C#
using System;

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

            Console.Write("Enter number of rows: ");
            if (!int.TryParse(Console.ReadLine(), out rows) || rows < 1)
            {
                Console.WriteLine("Please enter a positive whole number.");
                return;
            }

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

                Console.WriteLine();
            }
        }
    }
}

How It Works

1. Validate rows. TryParse rejects non-numeric input; require rows >= 1.

2. Same triangle. Only the outer bound changes from the literal 5.

Example 3 — Fixed-Width Columns

Use {0,3} so single- and double-digit products stay aligned.

C#
using System;

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

            for (i = 1; i <= 5; i++)
            {
                for (j = 1; j <= i; j++)
                    Console.Write("{0,3}", i * j);

                Console.WriteLine();
            }
        }
    }
}

How It Works

1. Same products. Still i * j for j = 1..i.

2. Alignment. Width 3 pads each value so columns line up when digits grow.

Edge Cases & Pitfalls

Check these before calling the solution done.

j <= rows

Inner loop always to rows

That prints a full rectangle (multiplication table). Keep j <= i for the triangle.

j * i

Swap to j * i only

Same products — fine. Just stay consistent; both equal i * j.

WriteLine

WriteLine inside the inner loop

That puts every product on its own line. Call WriteLine only after the column loop.

rows = 1

Single row

Output is just 1 — one product on one line.

no space

Print products without a separator

Digits run together (24812). Keep a space or fixed width between values.

Bad input

Convert.ToInt32 throws

Prefer int.TryParse so non-numeric input does not crash the program.

Time and Space Complexity

ProgramTimeExtra space
Fixed / aligned (Examples 1, 3)O(n²)O(1)
User input (Example 2)O(n²)O(1)

Total products are 1 + 2 + … + n = n(n+1)/2, so work is quadratic in the row count.

Key Takeaways

  • Rule: on row i, print i*j for j = 1..i; last value is i*i.
  • Shape: triangular — row length grows with i; total prints = n(n+1)/2.
  • Write vs WriteLine: products stay on the line; WriteLine advances after each row.
  • Next step: Program 50 prints a mixed descending/ascending number triangle.

One line: for each row i, print the first i multiples of i.

Frequently Asked Questions

A triangle where row i contains i values: i*1, i*2, … up to i*i. Row 4 prints 4 8 12 16.
Outer loop sets row i. Inner loop runs j = 1..i and prints i*j for each column.
The last value on row i is i*i. For i = 5, that is 25.
Yes — change the loop limit or read rows from user input with TryParse — see Example 2.
Change the inner loop to j = 1..rows on every row: for (j = 1; j <= rows; j++).
O(n²) for n rows because total prints are 1+2+…+n = n(n+1)/2.
Program 48 is a 1D powers-of-11 sequence with one loop. Program 49 uses nested loops for a multiplication triangle.
Use fixed-width formatting like Console.Write("{0,3}", i * j) so columns line up — see Example 3.
Yes — the inner loop count changes per row (j = 1..i), which requires nested loops.

Did you know?

On row i, print i products: i*1, i*2, … up to i*i. Total prints = n(n+1)/2 — a triangular number, so time is O(n²).

Next: Mixed Number Triangle

Print rows that descend then ascend (12345, 21234, 32123…).

Program 50 tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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.

6 people found this page helpful