Shape Rule
Repeat letter, grow width
Row 1 prints E, row 2 prints DD, up to AAAAA on the last line.

Same repeating idea as Program 9, but letters run E → D → C → B → A while row widths still grow 1, 2, 3, 4, 5. This tutorial covers the shape rule, letter formula, a live preview, worked C examples, edge cases, and complexity.
Repeat letter, grow width
Row 1 prints E, row 2 prints DD, up to AAAAA on the last line.
Rows + letter formula
for (i = 1; i <= rows; i++) walks each line; derive the letter from i.
Repeat count
for (j = 1; j <= i; j++) prints ch exactly i times — not j.
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 reverse repeating triangle in the browser.
Complexity
Total letters = n(n+1)/2; extra memory stays O(1).
A reverse repeating alphabet triangle grows 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 a staircase of identical letters per row.
In C you usually solve it with two nested for loops: the outer loop picks the row index, ch = top - i + 1 picks the letter, the inner loop prints that letter i times, then printf("\n") moves to the next line.
It locks in the difference between “which letter” (outer loop) and “how many times” (inner loop). Once that clicks, forward repeats, pyramids, and letter-countdown variants become much easier.
Rows use E, then D, then C … down to A.
Row widths are still 1, 2, 3, … like Program 9.
printf("%c", ch) in the inner loop; printf("\n") after.
Same shape — reverse letter direction only.
In short: for each row i, set ch = top - i + 1, print ch exactly i times, then call printf("\n").
Given a positive integer rows (or a fixed top letter like 'E'), print a left-aligned triangle where each row repeats one letter and letters count downward.
// First 5 rows (conceptual shape)
// E
// DD
// CCC
// BBBB
// AAAAA | Item | Type | Description |
|---|---|---|
rows | int | Number of triangle lines (typically 1–26). Top letter = 'A' + rows - 1. |
| Printed output | text | Left-aligned rows; row k repeats letter top - (k-1) exactly k times. |
top = 'A' + rows - 1
for i from 1 to rows:
ch = top - i + 1
for j from 1 to i:
print ch (no newline)
print newline | Approach | Idea | Best for |
|---|---|---|
| Nested int loops + formula | ch = top - i + 1, then print ch i times | Learning and interviews |
putchar(ch) | Write each letter without a format string | Leaner style after loops click |
| Goal | Pattern |
|---|---|
| Walk each row | for (i = 1; i <= rows; i++) |
| Letter for row i | ch = (char)(top - i + 1); |
| Print row letter | printf("%c", ch); — not j |
| End the row | printf("\n"); |
| putchar style | putchar(ch); then putchar('\n'); |
| Forward letters | See Program 9 (A, BB, 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 letter direction vs repeat count.
Flip letter direction while keeping the same growing widths.
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 reverse repeating alphabet triangle in the browser.
Three complete C programs — fixed top letter, scanf input, and a putchar shortcut. Click View Output to reveal sample console results.
Print five rows with classic nested loops and ch = 'E' - i + 1.
'E' down to 'A'Hard-coded five rows — ideal for first demos and screenshots.
#include <stdio.h>
int main() {
int i, j;
char ch;
for (i = 1; i <= 5; ++i) {
ch = (char)('E' - i + 1);
for (j = 1; j <= i; ++j) {
printf("%c", ch);
}
printf("\n");
}
return 0;
} When i = 1, ch becomes 'E' and the inner loop prints it once. When i = 2, ch is 'D' and you get DD, and so on until AAAAA. Printing ch (not j) keeps each row uniform.
Let the user choose the height at runtime.
Compute startChar = 'A' + rows - 1, then ch = startChar - i + 1. Check scanf in real apps.
#include <stdio.h>
int main() {
int rows, i, j;
char ch;
int startChar;
printf("Enter the number of rows: ");
scanf("%d", &rows);
startChar = 'A' + rows - 1;
for (i = 1; i <= rows; ++i) {
ch = (char)(startChar - i + 1);
for (j = 1; j <= i; ++j) {
printf("%c", ch);
}
printf("\n");
}
return 0;
} For rows = 4, startChar is 'D'. Row 1 prints D, row 2 prints CC, and so on. Clamp rows to 1–26 so startChar 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, then end the row with putchar('\n').
#include <stdio.h>
int main() {
int i, j;
char ch;
for (i = 1; i <= 5; ++i) {
ch = (char)('E' - i + 1);
for (j = 1; j <= i; ++j) {
putchar(ch);
}
putchar('\n');
}
return 0;
} putchar(ch) writes one character without a format string. Same 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. Fix the top letter (e.g. 'E') or compute it from rows.
for (i = 1; i <= rows; i++) selects the row; ch = top - i + 1 picks the letter.
for (j = 1; j <= i; j++) prints ch with printf("%c", ch) exactly i times.
printf("\n") ends the row so the next outer iteration starts fresh with a new letter.
Total letters: 1+2+…+n = n(n+1)/2 — O(n²) time, O(1) extra memory.
'E' down to 'A'Trace each outer-loop row index i, the derived letter ch, and how many times the inner loop runs.
i | ch | Printed row | Repeats |
|---|---|---|---|
1 | 'E' | E | 1 |
2 | 'D' | DD | 2 |
3 | 'C' | CCC | 3 |
4 | 'B' | BBBB | 4 |
5 | 'A' | AAAAA | 5 |
Total letter prints: 1 + 2 + 3 + 4 + 5 = 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 reverse repeating alphabet patterns.
j Instead of iRows become countdown sequences instead of repeated letters.
→ Always printf("%c", ch) for this shape — not j.
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 reverse repeating alphabet triangle is a small nested-loop exercise with lasting payoff: outer letter vs inner count, ch = top - i + 1, 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 9 or continue to the next alphabet pattern.
Derive ch with top - i + 1, print with printf("%c", ch), end rows with printf("\n"), 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 reverse repeating triangle the beginner-friendly way.
Letters down, width up
DefinitionPicks the row letter
CodeRepeats with printf
CodeEnds each row
I/OO(n²) time
AnalysisThis pattern is the reverse of Program 9: row widths still grow 1, 2, 3, …, but letters run backward (E, then D, then C, …). Use ch = top - i + 1 then print ch exactly i times so each row stays uniform.
Keep building letter patterns with nested loops and char math.
12 people found this page helpful