A triangular multiplication pattern prints row i as the products i×1, i×2, …, i×i. Each row is one longer than the row above — a classic nested-loop drill.
Remember
Rule: for i from 1 to rows
for j from 1 to i: print i * j
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25 ← rows = 5
Follows the powers-of-11 sequence in Program 48; next is the mixed descending/ascending triangle in Program 50.
Approach
How to Solve It
Outer loop picks the row multiplier i. Inner loop runs j = 1..i and prints i * j. End the row with printf("\n").
Method
Idea
Best for
Growing inner bound
Outer i = 1..rows; inner j = 1..i; print i*j
Learning, interviews, exams
Fixed-width print
printf("%4d", i * j)
Aligned columns for larger products
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
Pick each row
for (i = 1; i <= rows; i++)
Print products
for (j = 1; j <= i; j++)
Cell value
i * j
End of row
printf("\n");
Last value on row
i * i (row 5 ends with 25)
Printing Numbers vs Starting a New Line
API
Effect
Use for
printf("%d ", i * j)
Stays on the same line
Each product on the row
printf("\n")
Ends the current line
After the inner loop
Print all products without a newline, then end the row once.
Try it
Live Preview
Change the row count and the multiplication triangle updates instantly — capped at 12 for readable demos.
Whole numbers from 1 to 12. Tap a chip or type a value — the preview redraws as you go.
Live resultrows = 5 · 15 cells
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
Trace
Worked Walkthrough — Row i = 4
Trace the inner loop when the outer index is 4 — four products ending with 16.
j
i * j
Prints
1
4 * 1
4
2
4 * 2
8
3
4 * 3
12
4
4 * 4
16
Full row: 4 8 12 16. For n rows, total cells = n(n+1)/2 → O(n²).
Code
C Programs
Three complete programs: fixed rows = 10, scanf input, and a compact rows = 5 demo. Use View Output to reveal sample results.
Example 1 — Fixed rows = 10
Hard-coded height — outer loop picks row i, inner loop prints i * j.
C
#include <stdio.h>
int main(void)
{
int i, j;
for (i = 1; i <= 10; i++)
{
for (j = 1; j <= i; j++)
printf("%d ", i * j);
printf("\n");
}
return 0;
}
1. Outer loop.i runs from 1 to 10 — each pass is one row and the base multiplier.
2. Inner loop.j runs from 1 to i, so row i has exactly i values.
3. Product. Each cell prints i * j; the last value on the row is always i * i.
Example 2 — User Input Rows
Read rows with scanf and reject non-positive values.
C
#include <stdio.h>
int main(void)
{
int rows;
int i, j;
printf("Enter number of rows: ");
if (scanf("%d", &rows) != 1 || rows <= 0)
{
printf("Please enter a positive integer.\n");
return 1;
}
for (i = 1; i <= rows; i++)
{
for (j = 1; j <= i; j++)
printf("%d ", i * j);
printf("\n");
}
return 0;
}
Output (when user enters 4)
Enter number of rows: 4
1
2 4
3 6 9
4 8 12 16
How It Works
1. Prompt and validate. Reject bad input with a clear message.
2. Same core. Only the outer loop limit comes from the user — i * j logic stays identical.
3. Safer input tip. Cap demos for readable console output:
Safer input
if (scanf("%d", &rows) != 1 || rows < 1 || rows > 12)
{
printf("Enter a whole number from 1 to 12.\n");
return 1;
}
Example 3 — Compact rows = 5
Same nested loops with a smaller height for quick paper tracing.
C
#include <stdio.h>
int main(void)
{
int i, j;
for (i = 1; i <= 5; i++)
{
for (j = 1; j <= i; j++)
printf("%d ", i * j);
printf("\n");
}
return 0;
}
Output
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
How It Works
1. Same structure. Only the outer limit changes from 10 to 5.
2. Trace on paper. For i = 3: print 3, 6, 9 — three products ending with i*i.
3. Scale up next. Once the small demo is clear, use Examples 1–2 for 10 rows or user input.
Edge Cases & Pitfalls
Check these before calling the solution done.
j <= rows
Rectangle instead of triangle
If the inner loop uses j <= rows every row, you get a full table. Keep j <= i for the triangle.
\n inside
Broken rows
If printf("\n") sits inside the inner loop, each product lands on its own line. Call the newline only after the inner loop.
j * j
Wrong product
Printing j * j gives squares, not the row multiples. Use i * j.
rows = 1
Single row
Output is just 1 — a good sanity check for input validation.
alignment
Uneven columns
For larger rows, %d looks jagged. Switch to printf("%4d", i * j) when you want neat columns.
scanf
Check the return value
If scanf fails, rows may be uninitialized — always test scanf(...) == 1.
Analysis
Time and Space Complexity
Program
Time
Extra space
Fixed / input (Examples 1–2)
O(n²)
O(1)
Compact rows = 5 (Example 3)
O(n²)
O(1)
Total prints = 1 + 2 + … + n = n(n+1)/2. For n = 10 that is 55 cells; for n = 5 that is 15.
Remember
Key Takeaways
Rule: on row i, print i*1, i*2, …, i*i.
Growing bound: inner loop stops at i, not at rows — that is what makes the triangle.
Break the row: call printf("\n") only after the inner loop.
Complexity:O(n²) time from n(n+1)/2 cells; O(1) extra space.
One line: for i = 1..rows, print i*j for j = 1..i, then printf("\n").
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 scanf.
Change the inner loop to j = 1..rows every row so each row has the same width.
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 printf("%4d", i * j) so columns line up for larger products.
🤔
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²).