A reverse alphabet decreasing triangle prints shrinking reverse runs that always end at A — each row drops the leftmost letter from the row above.
Remember
Rule: start letter i walks top..A; print j from i..A
EDCBA
DCBA
CBA
BA
A ← 5 rows (top = E)
Unlike Program 8 (always starts at E and shortens the tail), here the first letter moves: E, then D, then C… while every row still ends on A.
Approach
How to Solve It
Both loops run backward: the outer picks the row start, the inner prints from that start down to A.
Method
Idea
Best for
Char countdown
Outer i from top..A; inner j from i..A
Learning, interviews, fixed demos
Row count
top = 'A' + rows - 1, then same loops
User input for height
Pseudocode
Pseudocode
top = 'A' + rows - 1
for i from top down to 'A':
for j from i down to 'A':
print j (no newline)
print newline
Cheat sheet
Goal
Pattern
Pick the row start
for (char i = top; i >= 'A'; i--)
Print i..A
for (char j = i; j >= 'A'; j--) printf("%c", j);
Compute top from rows
top = (char)('A' + rows - 1);
Spaced letters
printf("%c ", j);
End the row
printf("\n");
A–Z-safe height
Clamp rows to 1–26
Printing Letters vs Starting a New Line
API
Effect
Use for
printf("%c", j)
Stays on the same line
Each letter on the row
printf("\n")
Ends the current line
After the inner loop
Print characters without a newline, then end the row once.
Try it
Live Preview
Change the row count and the reverse decreasing triangle updates instantly — including top letter and letter totals.
Whole numbers from 1 to 10. Top letter is A + rows - 1; total letters equal n(n+1)/2.
Live result5 rows · top E · 15 letters
EDCBA
DCBA
CBA
BA
A
Trace
Worked Walkthrough — top = 'E'
Trace each start letter i and the reverse run printed from i down to A.
i
Inner j
Printed row
Count
E
E..A
EDCBA
5
D
D..A
DCBA
4
C
C..A
CBA
3
B
B..A
BA
2
A
A..A
A
1
Total letters: 5 + 4 + 3 + 2 + 1 = 15 = n(n+1)/2. Every row ends on A because the inner loop always stops there.
Code
C Programs
Three complete programs: fixed top E, row-count input, and spaced letters. Use View Output to reveal sample results.
Example 1 — Fixed Top E
Outer loop chooses the starting letter (E down to A). Inner loop prints from that start down to A.
C
#include <stdio.h>
int main() {
char i, j;
for (i = 'E'; i >= 'A'; i--) {
for (j = i; j >= 'A'; j--) {
printf("%c", j);
}
printf("\n");
}
return 0;
}
Output
EDCBA
DCBA
CBA
BA
A
How It Works
1. Outer loop picks the start.i walks E, D, C, B, A — the first letter on each row.
2. Inner loop prints down to A. From i down to 'A'. When i = 'C', that is CBA.
3. Break the line.printf("\n") after the inner loop starts the next shorter reverse run.
Example 2 — Row Count Input
Read the number of rows and compute top = 'A' + rows - 1. Check scanf in real apps.
C
#include <stdio.h>
int main() {
int rows;
char top, i, j;
printf("Enter the number of rows: ");
scanf("%d", &rows);
top = (char)('A' + rows - 1);
for (i = top; i >= 'A'; 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
DCBA
CBA
BA
A
How It Works
1. Map rows → top. For 4 rows, top becomes 'D'.
2. Same nested-loop core. Only the bounds follow top instead of the literal 'E'.
3. Safer input tip. Check scanf and stay within A–Z:
Safer input
if (scanf("%d", &rows) != 1 || rows < 1 || rows > 26) {
printf("Enter a row count 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() {
char top = 'E';
char i, j;
for (i = top; i >= 'A'; i--) {
for (j = i; j >= 'A'; j--) {
printf("%c ", j);
}
printf("\n");
}
return 0;
}
Output
E D C B A
D C B A
C B A
B A
A
How It Works
1. Same bounds. Outer and inner loops match Example 1 — only the printed unit changes.
2. Letter plus space.printf("%c ", j) makes columns easier to read at a glance.
3. Compact tip. Trim trailing spaces later if you need a tight line without a final space.
Edge Cases & Pitfalls
Check these before calling the solution done.
j from top
Wrong pattern
Starting the inner loop at top every row (instead of i) prints Program 8 style — always beginning with E.
Ascending j
Forward letters
Counting j upward prints ABCDE-style suffixes. Keep j descending from i to A.
Missing \\n
One long line
Call printf("\n") after each inner loop. Without it, every letter lands on one line.
rows = 1
Single A
Output is just A — a good sanity check.
Past Z
Clamp to 26
More than 26 rows walks top past Z. Cap or reject the input.
scanf fail
Unchecked input
Always check scanf("%d", &rows) == 1 so bad input does not leave rows uninitialized.
Analysis
Time and Space Complexity
Program
Time
Extra space
Fixed / input / spaced forms
O(n²)
O(1)
Total letters printed = n + (n-1) + … + 1 = n(n+1)/2, which is quadratic in the number of rows.
Remember
Key Takeaways
Both loops decrement: start letter walks top..A; each row prints i..A.
Right edge is A: every row ends at A while the left side walks backward.
Vs Program 8: start letter changes each row; it does not stay fixed at E.
Complexity:O(n²) time; O(1) extra space.
One line: for each start letter counting down, print start..A, then printf("\n").
Frequently Asked Questions
The outer loop picks the starting letter (E, then D, then C…). The inner loop prints from that start down to A, so the first line is EDCBA and each next line drops the previous leftmost letter.
The outer loop decreases the starting letter each row, and the inner loop decreases letters within that row down to A. That matches the reverse-alphabet output.
Program 6 prints forward suffixes ending at E (ABCDE, BCDE, …). This pattern prints reverse runs ending at A (EDCBA, DCBA, …). Same shrinking widths; opposite letter direction.
Program 8 always starts each row at E and shortens the tail (EDCBA, EDCB, EDC). Program 7 changes the first letter each row (E, then D, then C…).
Because the inner loop condition includes j == 'A', so the final character printed on each row is always A.
O(n²) for n rows, because total printed characters are n(n+1)/2.
Yes. Read rows with scanf, set top = (char)('A' + rows - 1), then loop i from top down to 'A' and print j from i down to 'A'.
Check scanf("%d", &rows) == 1, require n ≥ 1, and cap at 26 so the top letter stays within A–Z.
🤔
Did you know?
This triangle prints reverse letters and shrinks each row: EDCBA, DCBA, CBA, BA, A. Both loops run backward so letters move toward 'A' on every line.