A reverse-order alphabet triangle prints a left-aligned staircase where each row’s highest letter grows forward, but letters along the row print backward down to A.
Remember
Rule: on row with peak i, print i down to A
A
BA
CBA
DCBA
EDCBA ← 5 rows
It is the row-order flip of Program 1: same growing widths, but the inner loop counts down instead of up. Compare with Program 3, which changes the start letter while still printing forward.
Approach
How to Solve It
Two ways to emit the same shape — nested char loops, or the same loops with spaced letters for readability.
Method
Idea
Best for
Nested char loops
Outer = peak letter; inner = peak down to A
Learning, interviews, exams
Spaced letters
Same loops; print "%c " per letter
Easier column scanning once loops click
Pseudocode
Pseudocode
for peak from 'A' to lastLetter:
for ch from peak down to 'A':
print ch (no newline)
print newline
Change the row count and the reverse-order triangle updates instantly — every row ends at A.
Whole number from 1 to 10. Tap a chip or type a count — the preview redraws as you go.
Live result5 rows · peak E · 15 letters
A
BA
CBA
DCBA
EDCBA
Trace
Worked Walkthrough — Top = E (5 rows)
Trace each peak letter and the resulting reverse run down to A.
i (peak)
Inner range
Printed row
A
A..A
A
B
B..A
BA
C
C..A
CBA
D
D..A
DCBA
E
E..A
EDCBA
Row lengths are 1, 2, 3, 4, 5. The right edge is always A.
Code
C Programs
Three complete programs: fixed top E, row-count input with scanf, and spaced letters. Use View Output to reveal sample results.
Example 1 — Fixed Top E
Outer loop picks the highest letter on each row; inner loop prints from that letter down to 'A'.
c
#include <stdio.h>
int main(void) {
char i, j;
for (i = 'A'; i <= 'E'; i++) {
for (j = i; j >= 'A'; j--) {
printf("%c", j);
}
printf("\n");
}
return 0;
}
Output
A
BA
CBA
DCBA
EDCBA
How It Works
1. Outer loop raises the peak.i runs from 'A' to 'E' — one peak letter per row.
2. Inner loop prints backward. For each row, j runs from i down to 'A'. When i = 'C', that prints CBA.
3. Break the line.printf("\n") after the inner loop ends the row.
4. Full last row. When i = 'E', the inner loop prints the full reverse run EDCBA.
Example 2 — Row Count Input
Read the number of rows and loop i from 'A' to 'A' + rows - 1. Check scanf in real apps.
c
#include <stdio.h>
int main(void) {
int rows;
char i, j;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 'A'; i < 'A' + rows; i++) {
for (j = i; j >= 'A'; j--) {
printf("%c", j);
}
printf("\n");
}
return 0;
}
Output (when user enters 4)
Enter the number of rows: 4
A
BA
CBA
DCBA
How It Works
1. Scale the peak. For 4 rows, i runs through A..D. Cap rows at 26 so the peak stays within A–Z.
2. Same core loops. Only the stop letter changes; the peak-grows / print-backward rule is unchanged.
3. Safer input tip. Prefer:
Safer input
if (scanf("%d", &rows) != 1 || rows < 1 || rows > 26) {
printf("Enter a whole number from 1 to 26.\n");
return 1;
}
Example 3 — Spaced Letters
Print a trailing space after each letter so columns are easier to scan.
c
#include <stdio.h>
int main(void) {
char i, j;
for (i = 'A'; i <= 'E'; i++) {
for (j = i; j >= 'A'; j--) {
printf("%c ", j);
}
printf("\n");
}
return 0;
}
Output
A
B A
C B A
D C B A
E D C B A
How It Works
1. Same bounds. Loop limits are unchanged — only the printed unit becomes "%c ".
2. Optional trim. Trim trailing spaces later if you need a compact line for grading scripts.
Edge Cases & Pitfalls
Check these before calling the solution done.
Inner j++
Wrong direction on the row
If the inner loop counts up, you get Program 1 (A, AB, ABC). Keep j-- from i down to 'A'.
Outer --
Shrinking from E instead
If the outer loop runs E..A with the same inner rule, you print an inverted reverse triangle. Start at A and go up.
printf("\n") inside
Column of letters
If printf("\n") is inside the inner loop, each letter lands on its own line. Print letters with %c; break the line only after the row.
rows = 1
Single A
When the peak is 'A', you print one row: A. A good sanity check.
rows > 26
Beyond Z
Cap at 26 (or reject) so the peak letter stays within A–Z.
scanf
Check return value
scanf("%d", &rows) can fail on empty or non-numeric text. Check == 1 and validate the range.
Analysis
Time and Space Complexity
Program
Time
Extra space
Nested loops (Examples 1–2)
O(n²)
O(1)
Spaced letters (Example 3)
O(n²)
O(1)
For n rows, total letters are 1 + 2 + … + n = n(n + 1)/2 — still quadratic in n.
Remember
Key Takeaways
Rule: peak letter grows A → top; print that letter down to A.
Fixed right edge: every row ends at A.
Break the row: call printf("\n") only after the inner loop.
Complexity:O(n²) time; O(1) extra space.
One line: for each peak from A up to top, print that letter backward down to A.
Frequently Asked Questions
The outer loop selects the highest letter on the row (A to E). The inner loop starts at that letter and decrements down to 'A', printing each character, so each row reads backward.
Because the inner loop always runs until j == 'A', so the last printed character on every row is A.
Program 1 prints forward along each row (A, AB, ABC). This pattern prints backward down to A (A, BA, CBA) while the left edge still grows A, B, C, …
Program 3 starts earlier each row but still prints forward to a fixed top (E, DE, CDE). This pattern starts later each row and prints backward to a fixed A.
O(n²) for n rows, because the total printed letters are 1+2+...+n = n(n+1)/2.
Yes. Read rows with scanf and loop i from 'A' to 'A' + rows - 1, with the inner loop counting down from i to 'A'.
Check scanf("%d", &rows) == 1, require n ≥ 1, and cap at 26 so the highest letter stays within A–Z.
Yes. Start from 'a' and loop the same way: outer i from 'a' up, inner j from i down to 'a'.
🤔
Did you know?
Each row starts one letter later (A, B, C, …), but prints backward down to A. For 5 rows, the output is A, BA, CBA, DCBA, EDCBA — the reverse of Program 1’s row order.