Right-Aligned Reverse Alphabet Pyramid in C

Beginner
⏱️ 7 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Nested Loops

What You’ll Learn

Companion to program 22: same fixed-width grid (" " and %2c), but each row prints a descending slice E down to the current row letter instead of a forward k++ stream.

Use a monospace font in the terminal so columns stay even.

⭐ Pattern Output

Five rows from 'E' down to 'A':

Output
        E
      E D
    E D C
  E D C B
E D C B A
1

Complete C Program ('A''E')

Character literals; equivalent to the reference using 69, 65, etc.

c
#include <stdio.h>

int main() {
    int i, j;

    for (i = 'E'; i >= 'A'; --i) {
        for (j = 'A'; j < i; ++j) {
            printf("  ");
        }
        for (j = 'E'; j >= i; --j) {
            printf("%2c", j);
        }
        printf("\n");
    }

    return 0;
}

🧠 How It Works

1

Outer i: EA

Top row is only E; bottom row prints the full reverse run E D C B A.

Descend
2

Padding j < i

For i = 'E', j runs AD: four times → eight spaces. For i = 'A', the loop body does not run.

Align
3

Letters Ei

printf("%2c", j) prints each letter in a width-2 field; j counts down so the segment reads E, E D, …

%2c
4

Row width

Padding pairs plus letter cells still fill a ten-column line for five letters (same grid as program 22).

Grid
=

Check

At i = 'C', two padding pairs then three %2c letters: E D C.

2

Variation — User Input

endChar = (char)('A' + rows - 1); outer i runs endChar down to 'A'.

c
#include <stdio.h>

int main() {
    int rows;
    int i, j;
    char startChar, endChar;

    printf("Enter the number of rows: ");
    scanf("%d", &rows);

    startChar = 'A';
    endChar = (char)('A' + rows - 1);

    for (i = endChar; i >= startChar; --i) {
        for (j = startChar; j < i; ++j) {
            printf("  ");
        }
        for (j = endChar; j >= i; --j) {
            printf("%2c", j);
        }
        printf("\n");
    }

    return 0;
}

💡 Tips for Enhancement

Try These

  • Mirror program 22: start at 'Z' for a taller pyramid if it fits the console
  • Swap to printf(" %c", j) and single-space padding after you count columns
  • Print lowercase by offsetting startChar / endChar

Avoid

  • Mixing one-space padding with %2c without re-checking alignment
  • Forgetting that j in printf("%2c", j) must stay in range for a printable row

Key Takeaways

1

The space loop runs i - 'A' times (4 down to 0 as i goes EA), so the first printed row has the most padding and the fewest letters.

2

The letter loop always ends at the current i, so the visible suffix is Ei.

3

%2c keeps each letter column two characters wide, matching " " padding.

4

O(n²) work for n rows.

❓ Frequently Asked Questions

The first only prints leading gaps; the second prints the descending letters. Splitting them keeps the control flow easy to read.
Yes. for (i = 69; i >= 65; i--) with the same inner bounds behaves the same; literals are just clearer for humans.
Program 22 advances one global k across the whole figure. Here each row reuses values from E downward through i via the second inner loop.
O(n²) for n rows.

Explore More C Alphabet Patterns!

Descending outer loops plus a dedicated padding loop are a standard way to right-align triangular text.

All Alphabet Patterns →
Did you know?

Letters printed on the row for outer i count 'E' - i + 1; summed over i = E … A that is again 1 + 2 + … + 5 = 15 characters, like program 22.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful