A reverse alphabet triangle with a fixed start keeps the same leftmost letter on every row and shortens only the right side — classic five-row sample: EDCBA, EDCB, EDC, ED, E.
Remember
Rule: left edge stays at top; floor i walks A..top; print j from top..i
EDCBA
EDCB
EDC
ED
E ← 5 rows (top = E)
Unlike Program 7 (first letter moves: E, then D, then C…), here every row begins at the same top letter while the stopping point rises.
Approach
How to Solve It
Outer loop raises the floor; inner loop always starts at top and counts down to that floor.
Method
Idea
Best for
Fixed floor walk
Outer i from A..top; inner j from top..i
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 'A' to top:
for j from top down to i:
print j (no newline)
print newline
Cheat sheet
Goal
Pattern
Raise the floor
for (char i = 'A'; i <= top; i++)
Print top..i
for (char j = top; j >= i; 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 fixed-start reverse 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
EDCB
EDC
ED
E
Trace
Worked Walkthrough — top = 'E'
Trace each floor letter i and the reverse run printed from E down to i.
i
Inner j
Printed row
Count
A
E..A
EDCBA
5
B
E..B
EDCB
4
C
E..C
EDC
3
D
E..D
ED
2
E
E..E
E
1
Total letters: 5 + 4 + 3 + 2 + 1 = 15 = n(n+1)/2. Every row starts on E because the inner loop always begins at top.
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 raises the stopping letter; inner loop always starts at E and counts down.
C
#include <stdio.h>
int main() {
char i, j;
for (i = 'A'; i <= 'E'; i++) {
for (j = 'E'; j >= i; j--) {
printf("%c", j);
}
printf("\n");
}
return 0;
}
Output
EDCBA
EDCB
EDC
ED
E
How It Works
1. Outer loop raises the floor.i walks A, B, C, D, E — the last letter allowed on each row.
2. Inner loop always starts at E. From 'E' down to i. When i = 'C', that is EDC.
3. Break the line.printf("\n") after the inner loop starts the next shorter reverse prefix.
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 = 'A'; i <= top; i++) {
for (j = top; j >= i; j--) {
printf("%c", j);
}
printf("\n");
}
return 0;
}
Output (when user enters 4)
Enter the number of rows: 4
DCBA
DCB
DC
D
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 = 'A'; i <= top; i++) {
for (j = top; j >= i; j--) {
printf("%c ", j);
}
printf("\n");
}
return 0;
}
Output
E D C B A
E D C B
E D C
E D
E
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 i
Wrong pattern
Starting the inner loop at i (instead of top) prints Program 7 style — changing the first letter each row.
j >= A
No shrinking
Using j >= 'A' instead of j >= i prints the full reverse run on every row.
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
Left edge is fixed: every row starts at top; the floor i walks A..top.
Inner starts at top: print top..i so the tail shortens, not the left edge.
Vs Program 7: first letter stays the same; it does not walk backward each row.
Complexity:O(n²) time; O(1) extra space.
One line: for each rising floor, print top..floor, then printf("\n").
Frequently Asked Questions
Because the inner loop always starts at the top letter (E in the 5-row example) and counts down. So the first printed character each row is always E.
The outer loop increases the stopping point for the inner loop. That shortens the tail each row, producing EDCBA, then EDCB, then EDC, and so on.
Program 7 changes the first letter each row (E, then D, then C…). Program 8 keeps the first letter fixed and only shortens the tail.
Program 5 prints forward prefixes from A (ABCDE, ABCD, …). This pattern prints reverse prefixes from a fixed top (EDCBA, EDCB, …). Same shrinking idea; opposite letter direction and left edge.
Every row would print the full reverse run (EDCBA each time) with no shrinking.
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 'A' to top and print j from top down to i.
Check scanf("%d", &rows) == 1, require n ≥ 1, and cap at 26 so the top letter stays within A–Z.
🤔
Did you know?
Every row begins with the same top letter because the inner loop always starts there. The outer loop only raises the stopping point, so the tail shortens: EDCBA, EDCB, EDC, ED, E.