New: 213 pattern programs with tested code in C, C++, Java and Python Explore patterns

Inverted Reverse Alphabet Triangle (E D C B A, D C B A)

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
  1. Inverted Reverse Alphabet Triangle output
  2. How the inverted reverse alphabet triangle works
  3. Inverted Reverse Alphabet Triangle in C
  4. Inverted Reverse Alphabet Triangle in C++
  5. Inverted Reverse Alphabet Triangle in Java
  6. Inverted Reverse Alphabet Triangle in Python
  7. Time and space complexity
  8. 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
Inverted Reverse Alphabet Triangle layout diagram, row by row (n = 5)
How each row of the inverted reverse alphabet triangle is built (n = 5). Blue cells are printed characters; grey dots are spaces.

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.

  1. Run the outer loop for i from 1 to n, one row per pass.
  2. Print n βˆ’ i + 1 letters (letter number n βˆ’ i + 2 βˆ’ j).
  3. Move to the next line.

Key takeaways

  • Each row has n βˆ’ i + 1 letters 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.

This tutorial was drafted with AI assistance. Spotted a mistake? Tell us and we fix it. Read our editorial policy.

Quick check: can you predict the output?

Answer from the code, then check. Every answer comes from the real output above.

Pattern 14 of 22 in String Patterns

 

Still stuck? Ask AI to explain this code

Opens your favourite AI with this page, ready to explain every loop step by step.

Authored by

Ghanendra Yadav runs Pattern Programs from Bangalore, India. The site started in 2020 to help students practise loops and logic through pattern programs in C, C++, Java and Python. Every program published here is compiled and run before it goes live, and the output shown is the real output.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.