Reverse Order Alphabet Triangle in C

What You’ll Learn
Build a right-angled triangle where the first character of each row moves forward in the alphabet (A, B, C, D, E), but each row is printed backward down to A: A, BA, CBA, DCBA, EDCBA.
Compare with program 1 (forward A, AB, ABC, …) and program 3 (left edge moves backward, letters forward along the row).
⭐ Pattern Output
For 5 rows:
A
BA
CBA
DCBA
EDCBAComplete C Program (Fixed Rows)
Use rows = 5. For each 0-based row index i, set currentChar = 'A' + i, then print currentChar - j for j = 0 to i.
#include <stdio.h>
int main() {
int rows = 5;
int i, j;
char currentChar;
for (i = 0; i < rows; ++i) {
currentChar = (char)('A' + i);
for (j = 0; j <= i; ++j) {
printf("%c", (char)(currentChar - j));
}
printf("\n");
}
return 0;
}🧠 How It Works
Outer loop: row index i
i runs from 0 to rows - 1. Row i will contain i + 1 characters.
High letter for this row
currentChar = 'A' + i is the leftmost (highest) letter on the row: A, B, C, D, E as i increases.
Inner loop: step down
printf("%c", currentChar - j) for j from 0 to i prints from the row’s high letter down toward A.
Right edge is always A
When j == i, you print ('A' + i) - i = 'A'. So the last character of every row is A.
Triangle shape
Same O(n²) work as other letter triangles: 1+2+…+n characters for n rows.
Variation — User Input Version
Read rows with scanf(); the same logic applies for any positive rows (watch that 'A' + i stays in the range you want).
#include <stdio.h>
int main() {
int rows, i, j;
char currentChar;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 0; i < rows; ++i) {
currentChar = (char)('A' + i);
for (j = 0; j <= i; ++j) {
printf("%c", (char)(currentChar - j));
}
printf("\n");
}
return 0;
}💡 Tips for Enhancement
Try These
- Use
'a'instead of'A'for lowercase output - For A, AB, ABC, … see program 1 or replace the inner print with
printf("%c", (char)('A' + j))on each row - Right-align the triangle with spaces if you want a pyramid-style layout
- Validate
scanfresults and reject negative or huge row counts
Avoid
- Using
currentChar + jwhen you want descending letters inside the row - Letting
rowsso large that'A' + ileaves the letter range you intend - Mixing 0-based
iwith formulas written for 1-based row numbers without adjusting
Key Takeaways
currentChar = 'A' + i raises the starting letter each row.
currentChar - j prints backward along the row as j increases.
The last character on row i is always 'A'.
Time complexity O(n²) for n rows.
❓ Frequently Asked Questions
currentChar is 'A' + i. The inner loop prints currentChar - j for j from 0 through i, so each step subtracts one from the letter.j would walk forward in the alphabet (C, D, E on row starting at C). This pattern needs to walk backward to A.Explore More C Alphabet Patterns!
Small changes to + and - on characters produce very different shapes.
Here the left column reads A, B, C, D, E while the right column is all A—the mirror image of patterns where the right column is fixed and the left moves.
12 people found this page helpful
