Shape Rule
Odd widths 1, 3, 5…
Each row prints the prefix A..end where end is A, C, E, G, I.

Each row is a block of letters from A through the next “odd step” in the alphabet: A, ABC, ABCDE, ABCDEFG, ABCDEFGHI. The outer loop uses i += 2 (A, C, E, G, I). Compare Program 1 (step 1) and Program 13 (running counter). Includes a live preview, worked C examples, edge cases, and complexity.
Odd widths 1, 3, 5…
Each row prints the prefix A..end where end is A, C, E, G, I.
Step by 2
for (i = 'A'; i <= 'I'; i += 2) picks the end letter.
Print A..i
for (j = 'A'; j <= i; ++j) restarts at A every row.
Same line / next line
Letters use printf("%c", j); end each row with printf("\n").
1–13 rows
Pick a row count and draw the odd-length triangle in the browser.
Complexity
Total letters = r²; extra memory stays O(1).
An odd-length alphabet triangle grows by two letters on each new line. Every row still starts at A, but the ending letter jumps A → C → E → G → I, so widths are 1, 3, 5, 7, 9.
In C you usually solve it with two nested for loops: the outer loop steps the end letter by 2, the inner loop prints A through that end letter, then printf("\n") moves to the next line.
It shows that changing only the outer step (1 vs 2) transforms Program 1 into an odd-width triangle — and that odd-number sums equal perfect squares, which makes complexity analysis concrete.
Row lengths are 1, 3, 5, 7, 9, …
Outer end letter jumps with i += 2.
Inner loop always restarts at A.
Odd sum identity: total prints equal r².
In short: outer loop ends at A, C, E, … with i += 2; each row prints A..i with printf("%c", j), then printf("\n").
Given a row count r (or a fixed odd-step ending letter like 'I'), print a left-aligned triangle of alphabet prefixes with odd lengths.
// First 5 rows (conceptual shape)
// A
// ABC
// ABCDE
// ABCDEFG
// ABCDEFGHI | Item | Type | Description |
|---|---|---|
rows / end letter | int / char | Number of odd-length lines (1–13 for A–Y), or last end letter such as 'I'. |
| Printed output | text | Left-aligned rows; row k prints letters from A through 'A' + 2*(k-1). |
for end in A, C, E, ... up to last:
for ch from A to end:
print ch (no newline)
print newline | Approach | Idea | Best for |
|---|---|---|
Char i += 2 | Outer end letter steps by two | Learning and interviews |
| Row index formula | end = 'A' + 2*(row-1) | Clearer when input is a row count |
| Goal | Pattern |
|---|---|
| Step end letters | for (i = 'A'; i <= 'I'; i += 2) |
| Print prefix A..i | for (j = 'A'; j <= i; ++j) printf("%c", j); |
| End the row | printf("\n"); |
| End from row index | end = 'A' + 2 * (row - 1); |
| Step-1 triangle | See Program 1 (A, AB, ABC, …) |
Same triangle — different roles for each tool.
same linePrints a letter without moving to the next line
new lineEnds the current row after the prefix is printed
odd endsJumps the ending letter A → C → E …
int stepIn C, i += 2 works with int i — no cast needed
Reach for this triangle when practicing loop steps and odd-width prefixes.
Change only the outer step from 1 to 2 for odd widths.
Practice += 2 on chars and int row formulas.
Odd sums equal squares — count printed letters for small r.
Next: symmetric alphabet rows with a star center.
This is a console teaching pattern — not how you build modern app screens.
Key benefit: one small program that links loop step size, odd widths, and the classic odd-sum = square identity.
Choose a row count between 1 and 13 and draw the odd-length alphabet triangle in the browser.
Three complete C programs — fixed through I, ending-letter input, and a row-count formula. Click View Output to reveal sample console results.
Print five odd-length rows with i += 2.
'I'Hard-coded ending letter — ideal for first demos and screenshots.
#include <stdio.h>
int main() {
int i, j;
for (i = 'A'; i <= 'I'; i += 2) {
for (j = 'A'; j <= i; ++j) {
printf("%c", j);
}
printf("\n");
}
return 0;
} When i = 'A', the inner loop prints A. When i = 'C', it prints ABC, and so on through ABCDEFGHI. With int i, i += 2 needs no cast (unlike C#’s (char)2).
Let the user choose the last ending letter.
Read an odd-step ending letter (A, C, E, …). Prefer validating a single A–Z character in real apps.
#include <stdio.h>
int main() {
int i, j;
char endChar;
printf("Enter the ending letter (e.g. E for A,C,E rows): ");
scanf(" %c", &endChar);
for (i = 'A'; i <= endChar; i += 2) {
for (j = 'A'; j <= i; ++j) {
printf("%c", j);
}
printf("\n");
}
return 0;
} Same nested-loop core as Example 1; only the outer upper bound changes. Prefer odd-step endings (A, C, E, …). The leading space in scanf(" %c", ...) skips leftover newlines.
Drive the pattern from a row count instead of an ending letter.
end = 'A' + 2*(row-1)Clear when the user enters how many rows to print.
#include <stdio.h>
int main() {
int rows = 5;
int row, j;
char end;
for (row = 1; row <= rows; ++row) {
end = 'A' + 2 * (row - 1);
for (j = 'A'; j <= end; ++j) {
printf("%c", j);
}
printf("\n");
}
return 0;
} Row 1 ends at A + 0, row 2 at A + 2, row 3 at A + 4, and so on. Clamp rows to 1–13 so end stays within A–Y.
#include <stdio.h> brings in printf / scanf. Choose a last end letter or a row count.
i takes A, C, E, G, I by using i += 2 (with int i).
j always starts at A and prints every letter up to the current i.
printf("\n") ends the row so the next outer iteration starts fresh.
Total letters: 1+3+…+(2r-1) = r² — O(r²) time, O(1) extra memory.
'I'Trace each outer-loop value of i and count how many letters the inner loop prints.
i | Inner j range | Printed row | Length |
|---|---|---|---|
'A' | 'A'..'A' | A | 1 |
'C' | 'A'..'C' | ABC | 3 |
'E' | 'A'..'E' | ABCDE | 5 |
'G' | 'A'..'G' | ABCDEFG | 7 |
'I' | 'A'..'I' | ABCDEFGHI | 9 |
Total letter prints: 1 + 3 + 5 + 7 + 9 = 25 = 5².
Where this tiny pattern (and its step-by-2 idea) shows up beyond the homework prompt.
Clearest demo that the outer increment controls width growth.
Example: change += 2 to += 1 and watch Program 1 appear.
Teach step size as a one-line difference between patterns.
Example: side-by-side A/AB/ABC vs A/ABC/ABCDE.
Count letters to see that odd totals equal squares.
Example: 5 rows → 25 = 5² prints.
Lowercase or spaced letters once the loops work.
Example: start from 'a' with the same += 2.
Square totals make O(r²) concrete without triangular formulas.
Example: r = 10 → 100 letter prints.
Practice both ending-letter and row-count APIs for the same shape.
Example: map rows=3 ↔ end='E'.
Pro Tip: say “outer picks the odd end letter, inner prints A through that end” before coding — that story prevents forgetting to restart at A.
Why this pattern earns a spot right after the classic A/AB/ABC triangle.
Wrong step size shows up immediately as consecutive widths instead of odd ones.
Only nested loops and a step of 2 — no arrays required.
Flip back to Program 1 by changing the outer step to 1.
Total work is exactly r² — memorable for interviews.
Pro Tip: learn the i += 2 version first; treat the row-index formula as an equivalent rewrite afterward.
Small habits that keep odd-length alphabet code clean.
int for the Outer IndexWith int i, write i += 2 — no cast needed (unlike C# char arithmetic).
Use A, C, E, …, Y when you want clean odd lengths from row 1.
Inner loop must begin at 'A' every row for this prefix shape.
Row 13 ends at Y; row 14 would leave A–Z.
Trace 3 rows (A / ABC / ABCDE) on paper before coding larger demos.
Pro Tip: if you get A, AB, ABC instead of A, ABC, ABCDE, you used step 1 instead of step 2.
Mistakes that commonly break odd-length alphabet patterns.
You get Program 1’s consecutive widths (A, AB, ABC, …).
→ Keep i += 2 (or 2*(row-1) for the end letter).
iSkipping A produces single letters or wrong prefixes.
→ Always for (j = 'A'; j <= i; ++j).
scanf(" %c")Without the leading space, a leftover newline can be read as the “letter.”
→ Prefer scanf(" %c", &endChar) after prompts, or drive the pattern from a row count.
scanfEmpty or multi-character input leaves endChar / rows uninitialized or wrong.
→ Check scanf’s return value; validate a single A–Z letter or a positive row count.
Beyond 13 rows the end letter leaves A–Z.
→ Clamp to 1–13 or stop when end > 'Z'.
Check these inputs before calling the solution done.
Output is just A on one line.
Prints A / ABC / ABCDE.
Still runs, but odd-length alignment from A is messier — prefer odd-step ends.
End letter Y; 13² = 169 prints.
Unchecked scanf fails silently — check the return value.
Same loops work with 'a' and += 2.
Try these variations to lock in the pattern.
r²r² — hence O(r²) time.A.int i and i += 2 — no cast needed.Quick Takeaway: outer loop steps the end letter by 2, inner loop prints A through that end, then break the line — that is the whole pattern.
| Program | Time | Extra space |
|---|---|---|
| Nested loops (Examples 1–3) | O(r²) | O(1) |
Because 1+3+…+(2r-1)=r², the letter count is exactly a perfect square.
The odd-length alphabet triangle is a small nested-loop exercise with lasting payoff: outer step size, prefix printing, and the odd-sum = square identity. Master the i += 2 version, then optionally drive it from a row count with 'A' + 2*(row-1).
Practice the three examples above, then continue to Program 15’s symmetric alphabet-with-stars pattern.
Step the end letter by 2, always restart the inner loop at A, and remember total prints equal r².
i += 2 (or the row-index end formula)'A' every rowr² when asked about complexityscanf(" %c", ...)Print the odd-length triangle the beginner-friendly way.
Odd widths via step 2
DefinitionEnd letters A, C, E…
CodePrints A..end each row
CodeEnds each row
I/OO(r²) time
AnalysisOdd numbers add up to perfect squares: 1+3+5+…+(2r-1)=r². That is why this pattern prints exactly r² letters for r rows — the same count that makes the complexity O(r²).
Next up: symmetric alphabet rows with stars filling the center.
12 people found this page helpful