C Reverse Alphabet Pyramid Pattern (Slice from E)

Beginner
7 min read
Updated: Sep 2026
3 programs
Live preview

What Is This Pattern?

A right-aligned reverse alphabet pyramid prints a growing reverse slice each row — from a single top letter down to a full E D C B A base — with padding so the block stays right-aligned.

Remember
Rule: for i from top down to 'A',
      print pads for A..(i-1), then letters top..i (width 2)

        E
      E D
    E D C
  E D C B
E D C B A     ← top = 'E' (monospace)

Companion to Program 22: same fixed-width grid (two spaces for pads + %2c for letters), but each row prints a reverse slice top..i instead of a running sequential counter.

How to Solve It

Two ways to emit the same shape — start with char loops, then optionally rewrite with int row indexes.

MethodIdeaBest for
Char loopsOuter i; pad A..(i-1); letters top..iLearning, interviews, exams
Int row indexPad n - row; print row letters from top downWhen you think in row numbers

Pseudocode

Pseudocode
for i from top down to 'A':
    for j from 'A' to (i - 1):
        print "  "
    for j from top down to i:
        print j in width-2 field
    print newline

Cheat sheet

GoalPattern
Countdown rowsfor (i = top; i >= 'A'; i--)
Pad cellsfor (j = 'A'; j < i; j++) printf(" ");
Reverse slicefor (j = top; j >= i; j--) printf("%2c", j);
End the rowprintf("\n");
Row countn = top - 'A' + 1
Pad count for ii - 'A' (4 when i is E)
Sequential twinProgram 22 (k++)

Printing Letters vs Starting a New Line

APIEffectUse for
printf(" ") / printf("%2c", j)Stays on the same lineEach pad cell and each letter
printf("\n")Ends the current lineAfter both inner loops

Print each cell without a newline, then end the row once.

Live Preview

Change the top letter and the right-aligned reverse pyramid updates instantly.

One letter from A to F. Tap a chip or type a letter — the preview redraws as you go.

Live result Top E · 5 rows · 15 letters
         E
       E D
     E D C
   E D C B
 E D C B A

Worked Walkthrough — Top = E

Trace each row’s pads, reverse slice, and printed line (each cell is width 2).

iPad cellsLettersPrinted row
E4EE
D3E DE D
C2E D CE D C
B1E D C BE D C B
A0E D C B AE D C B A

Row count = top - 'A' + 1 (5 for E). Letter total: 1 + 2 + 3 + 4 + 5 = 15 = 5×6/2.

C Programs

Three complete programs: fixed top letter, console input, and an int-index rewrite. Use View Output to reveal sample results.

Example 1 — Fixed A–E

Hard-coded top E — pad first, then print letters from E down to the current row letter.

C
#include <stdio.h>

int main(void)
{
    char 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 loop descends. i runs from 'E' down to 'A' — one row per letter.

2. Pad first. Print " " for each j from 'A' to i - 1 so the letters stay right-aligned.

3. Reverse slice. Print j from 'E' down to i with %2c (width-2 cells).

4. Break the line. printf("\n") after both inner loops starts the next row.

When i = 'C', pads run for A and B, then letters print E D C.

Example 2 — Top Letter Input

Read the top letter at runtime. Prefer validating a single A–Z character in real apps.

C
#include <stdio.h>

int main(void)
{
    char top, i, j;

    printf("Enter the top letter (like E): ");
    scanf(" %c", &top);

    for (i = top; i >= 'A'; i--)
    {
        for (j = 'A'; j < i; j++)
        {
            printf("  ");
        }

        for (j = top; j >= i; j--)
        {
            printf("%2c", j);
        }

        printf("\n");
    }

    return 0;
}

How It Works

1. Prompt and read. Ask for a top letter, then read it with scanf(" %c", &top) (leading space skips whitespace).

2. Same pad/letter core. Both the outer start and the letter-loop start use top.

3. Safer input tip. Prefer checking the read and requiring A–Z:

Safer input
if (scanf(" %c", &top) != 1 || top < 'A' || top > 'Z')
{
    printf("Enter one letter from A to Z.\n");
    return 1;
}

Example 3 — Int Row Index

Same shape with integer indexes: pad n - row cells, then print row letters from the top down.

C
#include <stdio.h>

int main(void)
{
    char top = 'E';
    int n = top - 'A' + 1;
    int row, s, k;

    for (row = 1; row <= n; row++)
    {
        for (s = 0; s < n - row; s++)
        {
            printf("  ");
        }

        for (k = 0; k < row; k++)
        {
            printf("%2c", (char)(top - k));
        }

        printf("\n");
    }

    return 0;
}

How It Works

1. Derive height. n = top - 'A' + 1 is 5 when top is 'E'.

2. Pad by row number. Row 1 pads n - 1 cells; the last row pads 0.

3. Letters from the top. Letter k is (char)(top - k) — row 1 prints E; row 5 prints E..A.

Edge Cases & Pitfalls

Check these before calling the solution done.

Single space

Broken alignment

Pads must be " " (two spaces) to match %2c. One space skews the pyramid in monospace output.

\n inside

Broken outline

If printf("\n") is inside either inner loop, each cell lands on its own line. Print pads and letters without a newline; end the row only after both loops.

j <= i

Extra pad cell

The pad loop must stop at j < i, not j <= i, or you insert one too many empty cells.

top = A

Single letter

Output is just a width-2 A cell. Pad loop never runs. A good sanity check.

top < A

Empty output

Outer loop never runs if top < 'A'. Validate A–Z before looping.

Bad scanf

Validate one letter

Check scanf(" %c", &top) == 1 and require top in A–Z before the outer loop.

Time and Space Complexity

ProgramTimeExtra space
Char loops (Examples 1–2)O(n²)O(1)
Int row index (Example 3)O(n²)O(1)

For n = top - 'A' + 1 rows, each row does up to O(n) pad + letter writes. Letter total = 1 + 2 + … + n = n(n + 1)/2.

Key Takeaways

  • Rule: for i from top down to 'A', pad A..(i-1), then print top..i.
  • Fixed width: use " " pads and %2c so every cell is two columns.
  • Break the row: call printf("\n") only after both inner loops.
  • Complexity: O(n²) time; O(1) extra space.

One line: for each row letter i from top down to A, print pads for A..(i-1), then letters top..i with width 2, then printf("\n").

Frequently Asked Questions

The first prints padding so the visible letters are right-aligned. The second prints letters from E (or your top letter) down to the current row letter i.
Each letter is printed in a width-2 field with printf("%2c", j), so two spaces keep empty cells the same width and the pyramid aligned in monospace output.
Program 22 uses one running counter k++ across all rows (A..O). Program 23 prints a reverse slice each row using the loop variable j (E..i).
printf("%2c", j) (or two spaces) stays on the same line for pads and letters. printf("\n") ends the row after both inner loops finish.
Yes. Change the second loop to always begin from your chosen top letter and decrement to the row letter — Example 2 does this with user input.
O(n²) for n rows because each row does O(n) work across the padding + letter loops.
Use scanf(" %c", &top), require A–Z (optionally toupper), and reject non-letters.
For top = E, when i is E you print 4 pad cells (A..D); when i is A you print 0. Pads = (i − A).

Did you know?

Outer i runs from E down to A. The first inner loop prints one " " per j with A <= j < i (so the block shifts left each row). The second loop prints letters from E down to i using %2c so each cell is 2 columns wide.

Next: Palindromic Pyramid

Move from reverse slices to mirrored letter rows (A, BAB, CBABC, …).

Program 24 tutorial →

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