Shape Rule
Repeat letter, grow width
First row prints EEEEE, then DDDD, down to a single A.

Same repeating idea as Program 9 and Program 10, but widths shrink while letters still run E → A: EEEEE, DDDD, CCC, BB, A. 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 EEEEE, then DDDD, down to a single A.
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 repeating triangle in the browser.
Complexity
Total letters = n(n+1)/2; extra memory stays O(1).
An inverted repeating alphabet triangle starts wide and shrinks by one repeated letter on each new line, counting letters downward from the top of the alphabet range. 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 per-row letter step. Once that clicks, growing repeats (Program 9), reverse growing (Program 10), and more letter variants become much easier.
Row widths are 5, 4, 3, …, 1 (for five rows).
Rows use E, then D, then C … down to A.
Print ch in the inner loop; decrement only after the newline.
Same letters as Program 10 — inverted widths like Program 5.
In short: for i from rows down to 1, print ch exactly i times, call printf("\n"), then ch--.
Given a positive integer rows (or a fixed top letter like 'E'), print a left-aligned inverted triangle where each row repeats one letter, widths shrink, and letters count downward.
// First 5 rows (conceptual shape)
// EEEEE
// DDDD
// CCC
// BB
// A | 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 the top letter rows times, then widths shrink while letters step down. |
ch = 'A' + rows - 1
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 = (char)('A' + rows - 1); |
| Print row letter | printf("%c", ch); — not j |
| End row + step letter | printf("\n"); then ch--; |
| putchar style | putchar(ch); then putchar('\n'); ch--; |
| Growing reverse | See Program 10 (E, DD, CCC, …) |
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 per-row letter step.
Invert the widths while letters still step E→A (or grow A→E in other variants).
Clear drill: outer = which letter, inner = how many copies.
Compute top = 'A' + rows - 1 and count down safely.
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 repeating alphabet triangle in the browser.
Three complete C programs — fixed inverted 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.
'E' down to 'A'Hard-coded five inverted rows — ideal for first demos and screenshots.
#include <stdio.h>
int main() {
int i, j;
char ch = 'E';
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 E five times. After the row, ch-- makes ch become 'D', then i = 4 prints DDDD, and so on until a single A. Printing ch (not j) keeps each row uniform.
Let the user choose the height at runtime.
Set ch = 'A' + rows - 1, then 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;
printf("Enter the number of rows: ");
scanf("%d", &rows);
ch = (char)('A' + rows - 1);
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 'D'. The first row prints DDDD, then CCC, and so on down to A. Clamp rows to 1–26 so the top letter stays 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 = 'E';
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 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 = 'E' (or 'A' + rows - 1).
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 previous letter for the next shorter row.
Total letters: 1+2+…+n = 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 | 'E' | EEEEE | 5 |
4 | 'D' | DDDD | 4 |
3 | 'C' | CCC | 3 |
2 | 'B' | BB | 2 |
1 | 'A' | A | 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 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.
'a' + rows - 1 as the top letterscanf 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 repeating alphabet triangle is a small nested-loop exercise with lasting payoff: shrinking width vs 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 Programs 9–10 or continue to the next alphabet pattern.
Start ch at the top letter, 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 repeating triangle the beginner-friendly way.
Letters down, width down
DefinitionShrinks the row width
CodeRepeats with printf
CodeEnds row, steps letter
I/OO(n²) time
AnalysisThis is the inverted twin of Program 10 and the upside-down version of Program 9: letters still step E→A, but widths shrink 5, 4, 3, …, 1. 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