The inverted reverse alphabet triangle starts with E D C B A and drops the first letter on each row: D C B A, then C B A, B A and finally A. Every row ends at A.
Quick answer: Row i prints n β i + 1 letters, starting at letter n β i + 1 and counting back. The letter at position j is 'A' + n β i + 1 β j, which reaches A at the end of every row.
This program is part of the String Patterns collection.
Table of contents8 sections
- Inverted Reverse Alphabet Triangle output
- How the inverted reverse alphabet triangle works
- Inverted Reverse Alphabet Triangle in C
- Inverted Reverse Alphabet Triangle in C++
- Inverted Reverse Alphabet Triangle in Java
- Inverted Reverse Alphabet Triangle in Python
- Time and space complexity
- Frequently asked questions
Inverted Reverse Alphabet Triangle output
Output (n = 5):
E D C B A D C B A C B A B A A

How the inverted reverse alphabet triangle works
Turning the descending alphabet triangle upside down gives this pattern. The row length now shrinks, and each row still counts back to A. Both the length and the first letter come from the same number, n β i + 1, so the code only needs that one expression.
- Run the outer loop for
ifrom1ton, one row per pass. - Print
n β i + 1letters (letter numbern β i + 2 β j). - Move to the next line.
Key takeaways
- Each row has
n β i + 1letters and ends at A. - The first letter of each row falls one step: E, D, C, B, A.
- Length and first letter share the expression
n β i + 1. - Reversing the outer loop turns it back into A, B A, C B A.
Inverted 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 <= n - i + 1; j++)
printf("%c ", 'A' + n - i + 2 - j - 1);
printf("\n");
}
return 0;
}Inverted 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 <= n - i + 1; j++)
cout << char('A' + n - i + 2 - j - 1) << " ";
cout << endl;
}
return 0;
}Inverted Reverse Alphabet Triangle in Java
public class InvertedReverseAlphabetTriangle {
public static void main(String[] args) {
int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i + 1; j++)
System.out.print((char) ('A' + n - i + 2 - j - 1) + " ");
System.out.println();
}
}
}Inverted Reverse Alphabet Triangle in Python
n = 5
for i in range(1, n + 1):
for j in range(1, n - i + 2):
print(chr(ord('A') + n - i + 2 - j - 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
Can I write it with a simpler formula?
Yes. Run the outer loop from n down to 1 and print 'A' + i β j. It gives the same output, because row i then has i letters ending at A.
How do I make each row start at E instead?
Print 'A' + n β j. Every row then starts at E and stops earlier each time: E D C B A, E D C B, 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.






