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

Reverse Alphabet Triangle (E, E D, E D C)

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
  1. Reverse Alphabet Triangle output
  2. How the reverse alphabet triangle works
  3. Reverse Alphabet Triangle in C
  4. Reverse Alphabet Triangle in C++
  5. Reverse Alphabet Triangle in Java
  6. Reverse Alphabet Triangle in Python
  7. Time and space complexity
  8. Frequently asked questions

Reverse Alphabet Triangle output

Output (n = 5):

E
E D
E D C
E D C B
E D C B A
Reverse Alphabet Triangle layout diagram, row by row (n = 5)
How each row of the reverse alphabet triangle is built (n = 5). Blue cells are printed characters; grey dots are spaces.

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.

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

Key takeaways

  • Every row starts at the n-th letter.
  • The letter 'A' + n − j goes back one step per position.
  • The row length i decides where each row stops.
  • The last row spells the first n letters 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.

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 8 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.