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.
Approach
How to Solve It
One nested loop: row multiplier outside, column factors inside.
Method
Idea
Best for
Product triangle
Print i * j for j = 1..i
Learning, interviews, exams
Fixed width
Same products with {0,3} columns
Neater 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
Goal
Pattern
Walk rows
for (i = 1; i <= rows; i++)
Walk columns
for (j = 1; j <= i; j++)
Print product
Console.Write((i * j) + " ");
Aligned columns
Console.Write("{0,3}", i * j);
End the row
Console.WriteLine();
Write vs WriteLine
API
Effect
Use for
Console.Write
Stays on the same line
Each product (plus space or width)
Console.WriteLine
Ends the current line
After the inner loop finishes a row
Try it
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 result5 rows · 15 products
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
Trace
Worked Walkthrough — rows = 4
Trace each row’s products from i*1 through i*i.
i
Products i*j
Printed row
1
1
1
2
2, 4
2 4
3
3, 6, 9
3 6 9
4
4, 8, 12, 16
4 8 12 16
Total products for n rows = n(n+1)/2. Last value on row i is always i*i.
Code
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();
}
}
}
}
Output
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
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();
}
}
}
}
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();
}
}
}
}
Output
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
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.
Analysis
Time and Space Complexity
Program
Time
Extra 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.
Remember
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²).