Shape Rule
Repeat letter, grow width
First row prints AAAAA, then BBBB, down to a single E.

Same inverted widths as Program 11, but letters advance A → E with ch++: AAAAA, BBBB, CCC, DD, E. This tutorial covers the inverted shape rule, ch++ after each row, a live preview, worked C examples, edge cases, and complexity.
Repeat letter, grow width
First row prints AAAAA, then BBBB, down to a single E.
Width shrinks
for (i = rows; i >= 1; i--) walks from widest row to narrowest.
Repeat count
for (j = 1; j <= i; j++) prints ch exactly i times, then ch++ after the row.
Same line / next line
Letters use printf("%c", ch); end each row with printf("\n").
1–26 rows
Pick a row count and draw the inverted forward repeating triangle in the browser.
Complexity
Total letters = n(n+1)/2; extra memory stays O(1).
An inverted forward repeating alphabet triangle starts wide and shrinks by one repeated letter on each new line, while letters advance forward from A. With the right angle on the left, the console shows an upside-down staircase of identical letters per row.
In C you usually solve it with two nested for loops: the outer loop counts width down from rows to 1, the inner loop prints ch that many times, then printf("\n") and ch++ prepare the next shorter row.
It locks in inverted outer bounds plus a forward per-row letter step. Once that clicks, Program 11 (letters down), Program 9 (growing widths), and more letter variants become much easier.
Row widths are still 5, 4, 3, …, 1 (for five rows).
Rows use A, then B, then C … up through E.
Print ch in the inner loop; increment only after the newline.
Same inverted widths — letters step forward instead of down.
In short: start ch = 'A'; for i from rows down to 1, print ch exactly i times, call printf("\n"), then ch++.
Given a positive integer rows, print a left-aligned inverted triangle where each row repeats one letter, widths shrink, and letters advance from A.
// First 5 rows (conceptual shape)
// AAAAA
// BBBB
// CCC
// DD
// E | Item | Type | Description |
|---|---|---|
rows | int | Number of triangle lines (typically 1–26). Top letter = 'A' + rows - 1. |
| Printed output | text | Left-aligned rows; first row repeats A rows times, then widths shrink while letters step forward. |
ch = 'A'
for i from rows down to 1:
for j from 1 to i:
print ch (no newline)
print newline
ch = ch + 1 | Approach | Idea | Best for |
|---|---|---|
| Nested int loops + ch++ | Outer width shrinks; print ch, then ch++ | Learning and interviews |
putchar(ch) | Write each letter without a format string | Leaner style after loops click |
| Goal | Pattern |
|---|---|
| Walk widths down | for (i = rows; i >= 1; i--) |
| Start letter | ch = 'A'; |
| Print row letter | printf("%c", ch); — not j |
| End row + step letter | printf("\n"); then ch++; |
| putchar style | putchar(ch); then putchar('\n'); ch++; |
| Letters step down | See Program 11 (EEEEE, DDDD, …) |
Same triangle — different ways to emit characters.
same linePrints the row letter without moving to the next line
new lineEnds the current row after all repeats are printed
leaner char I/OWrites one character without a format string
print chMaster the formula and nested loops before polishing with putchar
Reach for this triangle when practicing inverted widths plus a forward per-row letter step.
Keep the inverted widths, but advance letters A→E with ch++.
Clear drill: outer = which letter, inner = how many copies.
Start from 'A' (or 'a') and advance with ch++ after each row.
Lowercase, hollow borders, or centered pyramids next.
This is a console teaching pattern — not how you build modern app screens.
Key benefit: one small program that separates letter choice from repeat count — the skill behind most alphabet patterns.
Choose a row count between 1 and 26 and draw the inverted forward repeating alphabet triangle in the browser.
Three complete C programs — fixed inverted forward rows, scanf input, and a putchar shortcut. Click View Output to reveal sample console results.
Print five inverted rows with classic nested loops and ch++ after each line.
'A' up through 'E'Hard-coded five inverted rows — ideal for first demos and screenshots.
#include <stdio.h>
int main() {
int i, j;
char ch = 'A';
for (i = 5; i >= 1; --i) {
for (j = 1; j <= i; ++j) {
printf("%c", ch);
}
printf("\n");
ch++;
}
return 0;
} When i = 5, the inner loop prints A five times. After the row, ch++ makes ch become 'B', then i = 4 prints BBBB, and so on until a single E. Printing ch (not j) keeps each row uniform.
Let the user choose the height at runtime.
Keep ch = 'A'; loop i from rows down to 1 with ch++ after each row. Check scanf in real apps.
#include <stdio.h>
int main() {
int rows, i, j;
char ch = 'A';
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = rows; i >= 1; --i) {
for (j = 1; j <= i; ++j) {
printf("%c", ch);
}
printf("\n");
ch++;
}
return 0;
} For rows = 4, ch starts at 'A'. The first row prints AAAA, then BBB, and so on up to D. Clamp rows to 1–26 so letters stay within A–Z. Check scanf’s return value in safer labs.
Same shape using putchar instead of printf for each letter.
putchar(ch)Write each letter with putchar, end the row with putchar('\n'), then ch++.
#include <stdio.h>
int main() {
int i, j;
char ch = 'A';
for (i = 5; i >= 1; --i) {
for (j = 1; j <= i; ++j) {
putchar(ch);
}
putchar('\n');
ch++;
}
return 0;
} putchar(ch) writes one character without a format string. Same inverted forward nested-loop structure as Example 1; a leaner alternative to printf("%c", ch). Keep either style for exams that want both loop bounds visible.
#include <stdio.h> brings in printf / scanf. Set ch = 'A' (or keep it for any rows).
for (i = rows; i >= 1; i--) selects the current width from wide to narrow.
for (j = 1; j <= i; j++) prints ch with printf("%c", ch) exactly i times.
printf("\n") ends the row; ch++ steps to the next letter for the next shorter row.
Total letters: n+(n-1)+…+1 = n(n+1)/2 — O(n²) time, O(1) extra memory.
Trace each outer-loop width i, the current letter ch, and how many times the inner loop runs.
i | ch | Printed row | Repeats |
|---|---|---|---|
5 | 'A' | AAAAA | 5 |
4 | 'B' | BBBB | 4 |
3 | 'C' | CCC | 3 |
2 | 'D' | DD | 2 |
1 | 'E' | E | 1 |
Total letter prints: 5 + 4 + 3 + 2 + 1 = 15 = 5×6/2.
Where this tiny pattern (and its loop structure) shows up beyond the homework prompt.
Best demo that the printed value need not be the loop counter.
Example: swap printf("%c", ch) for something based on j and watch letters step.
Teach direction as a one-line change: increment vs decrement.
Example: side-by-side A/BB/CCC vs E/DD/CCC.
Practice 'A' + rows - 1 without complex algorithms.
Example: rows = 7 → top = 'G'.
Swap to lowercase or mix digits once the loops work.
Example: start from 'a' + rows - 1.
Triangular totals make O(n²) concrete for beginners.
Example: count printed letters for n = 10 → 55.
Pair the pattern with checked scanf and 1–26 clamps.
Example: reject rows <= 0 or rows > 26.
Pro Tip: when explaining this pattern, say “outer picks the letter, inner only counts” before writing any code — that story prevents printing j by mistake.
Why this pattern earns a spot right after the forward repeating triangle.
Wrong printed variable shows up immediately as stepping letters.
Only loops, chars, and console output — no arrays required.
Flip to Program 9 by counting letters upward instead.
Streaming output needs no storage beyond loop counters.
Pro Tip: learn the nested-loop printf version first; treat putchar as a polish shortcut afterward.
Small habits that keep alphabet-pattern code clean.
Use ch for the row letter and repeat (or k) for the count — clearer than overloaded i/j.
scanfVerify scanf returns 1 so bad input does not leave rows unset.
Only call printf("\n") after the inner loop finishes the row.
For A–Z demos, reject or clamp rows > 26.
Trace rows = 3 (C, BB, AAA) on paper before coding larger demos.
Pro Tip: if a row shows EDCBA-style sequences, you almost certainly printed j instead of i.
Mistakes that commonly break inverted forward repeating alphabet patterns.
j Instead of iRows become countdown sequences instead of repeated letters.
→ Always printf("%c", ch) for this shape — not j. Put ch++ after the row, not inside the inner loop.
Each letter lands on its own line — you get a column, not a triangle.
→ Use printf("%c", ch) for letters; printf("\n") only after the inner loop.
Omitting printf("\n") glues every letter onto one endless line.
→ Always end the row after the inner loop.
scanfLetters or empty input leave rows uninitialized.
→ Check scanf’s return value and re-prompt on failure.
'A' + rows - 1 can leave the A–Z range.
→ Clamp to 26 or define wrap/error behavior explicitly.
Check these inputs before calling the solution done.
Output is just A on one line.
Treat as invalid; re-prompt instead of silent empty output.
rows < 0Invalid height — validate before computing top.
Clamp or error — char math leaves A–Z.
Unchecked scanf fails silently — check the return value.
Same loops work with 'a' and 'a' + rows - 1.
Try these variations to lock in the pattern.
ch--'a' instead of 'A'scanf succeeds and 1 <= rows <= 26n(n+1)/2 — hence O(n²) time.1 <= rows <= 26 for interactive A–Z programs.Quick Takeaway: outer loop picks the letter (counting down), inner loop repeats it, then break the line — that is the whole pattern.
| Program | Time | Extra space |
|---|---|---|
| Nested loops (Examples 1–2) | O(rows²) | O(1) |
putchar (Example 3) | O(rows²) | O(1) |
The inverted forward repeating alphabet triangle is a small nested-loop exercise with lasting payoff: shrinking width vs forward letter step, ch++ after each row, and O(n²) intuition. Master the classic two-loop version, then optionally polish letter output with putchar.
Practice the three examples above, then compare with Program 11 or continue to the next alphabet pattern.
Start ch at 'A', shrink width with the outer loop, print with printf("%c", ch), end rows with printf("\n") then ch++, and clamp row counts to 1–26 when reading input.
printf("%c", ch) for letters and printf("\n") after each row1 <= rows <= 26 for interactive programsscanf’s return value instead of ignoring failed inputprintf("\n") inside the inner letter looprows > 26 without a clear policyPrint the inverted forward repeating triangle the beginner-friendly way.
Letters up, width down
DefinitionShrinks the row width
CodeRepeats with printf
CodeEnds row, advances letter
I/OO(n²) time
AnalysisThis is the forward-letter twin of Program 11: same inverted widths (5…1), but letters advance A→E with ch++ instead of stepping down. Print ch in the inner loop, then ch++ after each row so every line stays uniform.
Keep building letter patterns with nested loops and char math.
12 people found this page helpful