Shape Rule
Odd row lengths
Row 1 prints 1, row 2 prints 123, row 3 prints 12345, and so on — digits run together with no spaces.

The increasing odd-length number rows pattern uses i += 2 in the outer loop so each row prints 1..i with lengths 1, 3, 5, 7, 9 — a natural step after the jump triangle in Program 21. This tutorial covers the shape rule, step-size logic, a live preview, algorithm steps, worked C examples, edge cases, and complexity.
Odd row lengths
Row 1 prints 1, row 2 prints 123, row 3 prints 12345, and so on — digits run together with no spaces.
i += 2
for (i = 1; i <= max; i += 2) walks odd values 1, 3, 5, 7, 9 as row lengths.
1..i
for (j = 1; j <= i; j++) then printf("%d", j) — no space between digits.
Same line / next line
Digits use printf("%d", j); end each row with printf("\n").
1–15 max
Pick an odd maximum and draw the odd-length rows pattern instantly in the browser.
Complexity
Total prints = 1+3+5+...+max; extra memory stays O(1).
An increasing odd-length number rows pattern prints consecutive digits 1..i on each row, with row lengths growing by 2 each time. With max = 9, the output is 1, 123, 12345, 1234567, 123456789.
In C you use for (i = 1; i <= max; i += 2) in the outer loop and printf("%d", j) in the inner loop, then printf("\n") ends each row.
It introduces loop step sizes — a simple change to i += 2 creates a whole new family of patterns.
Row lengths are 1, 3, 5, 7, 9 — always odd.
printf("%d", j) concatenates digits on one line.
Digits run together — 123 not 1 2 3.
Follow Program 21; continue to Program 23 (number & asterisk mirror) next.
In short: for each odd i up to max, print digits 1 through i with printf("%d", j), then call printf("\n").
Given a positive odd integer max, print increasing odd-length rows: for each odd i from 1 to max, print digits 1 through i concatenated on one line.
// max = 9 (conceptual shape)
// 1
// 123
// 12345
// 1234567
// 123456789 | Item | Type | Description |
|---|---|---|
max | int | Maximum row length (typically odd, e.g. 9). |
i | int | Outer loop — odd values 1, 3, 5, … up to max. |
j | int | Inner loop — prints digits 1 through i. |
| Printed output | text | Row i has i concatenated digits — no spaces. |
for i from 1 to max step 2:
for j from 1 to i:
print j (no space)
print newline | Approach | Idea | Best for |
|---|---|---|
| Outer i += 2 | 1, 123, 12345, … | Learning and interviews |
| User-input max | scanf("%d", &max); | Flexible console programs |
| Inner j += 2 | 1, 13, 135, 1357, … | Odd-only digit rows |
| Goal | Pattern |
|---|---|
| Walk odd lengths | for (i = 1; i <= max; i += 2) |
| Print digits | for (j = 1; j <= i; j++) |
| Write digit | printf("%d", j); |
| End the row | printf("\n"); |
| Odd-only variant | for (j = 1; j <= i; j += 2) |
| User input | scanf("%d", &max); |
Same odd-length rows — different ways to control max and inner loop step.
i += 2Row lengths 1, 3, 5, 7, 9
printf("%d", j)Concatenate digits — no spaces
j += 2Print 1, 3, 5 only in Example 3
even maxSubtract 1 if user enters an even maximum
Reach for this pattern when teaching loop step sizes and concatenated digit output inside nested loops.
Natural follow-up after Program 21 — introduces outer loop step i += 2.
Outer/inner bound practice with an immediate visual check.
Combine loops with scanf for a flexible row count.
Compare Program 21 (jump triangle) and Program 23 (number & asterisk mirror) next.
This is a console teaching pattern — not how you build modern app screens.
Key benefit: one small program that locks in nested loops, output sequencing, and O(n²) thinking.
Choose an odd maximum between 1 and 15 and draw the odd-length rows pattern in the browser.
Three complete C programs — fixed maximum, user input, and odd-only digits variant. Click View Output to reveal sample console results.
Print five rows of odd-length consecutive digits with i += 2.
max = 9Hard-coded maximum — ideal for first demos and screenshots.
#include <stdio.h>
int main() {
int i, j;
for (i = 1; i <= 9; i += 2) {
for (j = 1; j <= i; ++j)
printf("%d", j);
printf("\n");
}
return 0;
} When i = 1, the inner loop prints 1 once. When i = 3, j runs 1, 2, 3 — output 123. When i = 9, digits 1 through 9 concatenate into 123456789. printf("\n") after the inner loop starts the next row.
Read the maximum with scanf instead of hard-coding 9.
Read max with scanf("%d", &max); adjust to odd if the user enters an even value.
#include <stdio.h>
int main() {
int max;
int i, j;
printf("Enter the maximum value: ");
scanf("%d", &max);
if (max % 2 == 0) max -= 1;
for (i = 1; i <= max; i += 2) {
for (j = 1; j <= i; ++j)
printf("%d", j);
printf("\n");
}
return 0;
} Same nested-loop core as Example 1; only the source of max changes. The if (max % 2 == 0) max -= 1 guard keeps the last row odd-length. Non-numeric input leaves max unset if you ignore scanf’s return value — always check it in safer labs.
Use j += 2 in the inner loop to print only odd digits.
j += 2Keep max = 9 but print 1, 3, 5, 7, 9 instead of 1..i on each row.
#include <stdio.h>
int main() {
int i, j;
for (i = 1; i <= 9; i += 2) {
for (j = 1; j <= i; j += 2)
printf("%d", j);
printf("\n");
}
return 0;
} Change only the inner loop to j += 2 — the outer loop and printf("\n") logic stay the same. Each row prints odd digits up to i instead of every digit from 1 to i.
#include <stdio.h> brings in printf / scanf. Set max and loop variables i, j.
for (i = 1; i <= max; i += 2) — row lengths are 1, 3, 5, 7, 9.
for (j = 1; j <= i; j++) then printf("%d", j) — digits concatenate with no spaces.
printf("\n") ends the row so the next outer iteration starts fresh.
Total prints grow as 1+3+5+...+max — O(n²) time, O(1) extra memory.
max = 9Trace each outer-loop value of i and the digits printed on each row.
i | Inner j range | Digits printed | Row output |
|---|---|---|---|
1 | 1 | 1 | 1 |
3 | 1..3 | 1, 2, 3 | 123 |
5 | 1..5 | 1, 2, 3, 4, 5 | 12345 |
7 | 1..7 | 1..7 | 1234567 |
9 | 1..9 | 1..9 | 123456789 |
Total digit prints: 1 + 3 + 5 + 7 + 9 = 25.
Where this tiny pattern (and its loop structure) shows up beyond the homework prompt.
Clearest visual proof that outer and inner bounds interact.
Example: change j <= i and watch the shape change.
Foundation for inverted, pyramid, diamond, and hollow variants.
Example: use (i + j) % 2 for row+column parity grids.
Practice printf vs row newline without complex math.
Example: put printf("\n") inside the inner loop by mistake.
Swap digits for letters, stars, or spaced output once the loop works.
Example: print j + " " for spaced digits on each row.
Triangular totals make O(n²) concrete for beginners.
Example: count printed digits for n = 10 still → 55.
Pair the pattern with scanf return checks and positive-row checks.
Example: reject max <= 0 and re-prompt.
Pro Tip: when an interviewer asks for patterns, explain the outer/inner roles first — then write the loops. The story matters as much as the code.
Why this pattern earns a permanent spot in beginner C courses.
Wrong bounds show up immediately as a broken staircase.
Only loops and console output — no arrays or math libraries.
Invert, center, hollow, or change the fill character with small edits.
Streaming output needs no storage beyond loop counters.
Pro Tip: learn i += 2 in the outer loop first; compare with j += 2 odd-digit variant in Example 3.
Small habits that keep number-pattern code clean.
Use printf("%d", j) without spaces — not printf("%d ", j) unless you want gaps.
scanfCheck the return value so bad input does not leave max uninitialized.
Only call printf("\n") after the inner loop finishes the row.
Write each odd i and the j range before coding.
Trace max = 7 on paper before coding larger demos.
Pro Tip: if the output is a vertical list of single digits per line, you almost certainly put printf("\n") inside the inner loop.
Mistakes that commonly break odd-length row patterns.
Each digit lands on its own line — you get a column, not a triangle.
→ Use printf("%d", j); printf("\n") only after the inner loop.
Using i++ prints every length 1, 2, 3, 4 — not odd lengths only.
→ Use for (i = 1; i <= max; i += 2) for odd row lengths.
printf("%d ", j) produces 1 2 3 instead of 123.
→ Use printf("%d", j) for concatenated digits.
Omitting printf("\n") glues every number onto one endless line.
→ Always end the row after the inner loop.
Letters or empty input leave max uninitialized.
→ Check scanf return value and re-prompt on failure.
Check these inputs before calling the solution done.
Output is just 1 on one line.
Outer loop never runs — print nothing or show a message.
max < 0Treat as invalid; re-prompt instead of silent empty output.
Output grows as n² characters — fine for labs, noisy for huge n.
Unchecked scanf leaves max unset — check the return value.
Subtract 1 to keep odd row lengths — see Example 2.
Try these variations to lock in the pattern.
printf("%d ", j) for gaps1+3+5+...+max — O(n²) for maximum row length n.printf("%d", j) stays on the line; printf("\n") advances — mix them carefully.max > 0 for interactive programs; max = 1 should print a single 1.Quick Takeaway: use i += 2 in the outer loop, printf("%d", j) in the inner loop, then printf("\n") after each row.
| Program | Time | Extra space |
|---|---|---|
| Nested loops (Examples 1–2) | O(max²) | O(1) |
| Odd digits (Example 3) | O(max²) | O(1) |
The increasing odd-length number rows pattern is a compact lesson in loop step sizes: use i += 2 in the outer loop and printf("%d", j) in the inner loop to concatenate digits. Master the fixed-max version, then try user input and the odd-only digit variant.
Practice the three examples above, then continue to Program 23 for the number & asterisk mirror pattern.
Use i += 2 for odd lengths — validate max and adjust even input when reading from the console.
for (i = 1; i <= max; i += 2) in the outer loopprintf("%d", j) — no space between digitsmax with max -= 1 for user inputscanf return value before using maxprintf("\n") inside the inner digit loopi++ when you want odd lengths onlymax = 1 edge casePrint the pattern the beginner-friendly way.
i += 2 rows
Definitionprintf("%d", j) no space
Code1, 3, 5, 7, 9
ShapeOdd digits variant
VariantO(n²) time
AnalysisEach row length increases by 2 because the outer loop uses i += 2 (1, 3, 5, 7, 9). The inner loop prints 1..i with no spaces — total prints grow as O(n²) for maximum row length n.
Move on to the number & asterisk mirror pattern in the C number-pattern series.
12 people found this page helpful