The reverse alphabet triangle counts backwards through the alphabet from the n-th letter. Every row starts at E and goes one letter further back: E, E D, E D C, down to E D C B A.
Quick answer: Row i prints i letters, each followed by a space. The letter at position j is 'A' + n − j, so position 1 is always the n-th letter, E for five rows, and each step to the right goes one letter back. The last row spells E D C B A.
This program is part of the String Patterns collection.
Table of contents8 sections
Reverse Alphabet Triangle output
Output (n = 5):
E E D E D C E D C B E D C B A

Same shape, other characters: the 0-1 (Binary) Triangle, Alphabet Triangle, Descending Alphabet Triangle, Hash (#) Right Triangle and Incremental Alphabet Triangle programs draw this same outline with different characters. Putting them side by side shows which part of the loop decides the shape and which part decides what is printed.
How the reverse alphabet triangle works
The value depends only on the position, not the row, which is why every row starts with the same letter. The row number only decides how many letters to print. It is the same idea as the reverse number triangle (5, 54, 543) with letters.
- Run the outer loop for
ifrom1ton, one row per pass. - Print
iletters (letter numbern − j + 1). - Move to the next line.
Key takeaways
- Every row starts at the
n-th letter. - The letter
'A' + n − jgoes back one step per position. - The row length
idecides where each row stops. - The last row spells the first
nletters backwards.
Reverse Alphabet Triangle in C
#include <stdio.h>
int main(void) {
int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++)
printf("%c ", 'A' + n - j + 1 - 1);
printf("\n");
}
return 0;
}Reverse Alphabet Triangle in C++
#include <iostream>
using namespace std;
int main() {
int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++)
cout << char('A' + n - j + 1 - 1) << " ";
cout << endl;
}
return 0;
}Reverse Alphabet Triangle in Java
public class ReverseAlphabetTriangle {
public static void main(String[] args) {
int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++)
System.out.print((char) ('A' + n - j + 1 - 1) + " ");
System.out.println();
}
}
}Reverse Alphabet Triangle in Python
n = 5
for i in range(1, n + 1):
for j in range(1, i + 1):
print(chr(ord('A') + n - j + 1 - 1), end=" ")
print()Time and space complexity
The program prints one character for each position in the pattern, so for n rows it runs in O(n²) time. It only needs a few loop variables, so the extra memory is O(1).
Frequently asked questions
How do I make each row end at A instead?
Print 'A' + i − j: each row then starts at its own letter and counts back to A, as in the descending alphabet triangle.
Why does every row start with E?
The letter is worked out from the position alone, and position 1 always gives the n-th letter. The row number only decides how many letters follow it.
How do I start from Z?
Use 'Z' − j + 1 as the letter. Row 1 is Z, row 2 is Z Y, and so on.
How do I let the user choose the number of rows?
Read n from the keyboard instead of fixing it in the code: scanf("%d", &n); in C, cin >> n; in C++, new Scanner(System.in).nextInt() in Java and int(input()) in Python.






