Reverse Centered Alphabet Pyramid in C

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

What You’ll Learn

This reverse centered alphabet pyramid reuses the row logic from program 28: run it while i steps down to 'A', then again while i steps up from 'B', so the middle line is not duplicated.

⭐ Pattern Output

Nine rows for 'A''E' (five down, four up after the center):

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

Complete C Program ('A''E')

Two phases share the same pair of inner loops.

c
#include <stdio.h>

int main() {
    int i, j;
    char k = 'E';

    for (i = k; i >= 'A'; --i) {
        for (j = k; j >= 'A'; --j) {
            if (j > i) {
                printf("%c ", j);
            } else {
                printf("%c ", i);
            }
        }
        for (j = 'B'; j <= k; ++j) {
            if (j > i) {
                printf("%c ", j);
            } else {
                printf("%c ", i);
            }
        }
        printf("\n");
    }

    for (i = 'B'; i <= k; ++i) {
        for (j = k; j >= 'A'; --j) {
            if (j > i) {
                printf("%c ", j);
            } else {
                printf("%c ", i);
            }
        }
        for (j = 'B'; j <= k; ++j) {
            if (j > i) {
                printf("%c ", j);
            } else {
                printf("%c ", i);
            }
        }
        printf("\n");
    }

    return 0;
}

🧠 How It Works

1

Upper half: i from E down to A

Each row is a full-width “floor” line: print spaces while a column index is above the floor letter i, print descending letters on the left side of the floor, the floor letter in the middle gap, then mirror letters ascending on the right. That matches the same nested-loop idea as the hollow square alphabet pattern, but repeated for every floor level.

Down
2

Center row at i == 'A'

The middle line is the widest inner sentence: E D C B A B C D E. Here the floor is A, so the left and right ramps meet with a single A between the descending and ascending halves.

A
3

Lower half: i from B back to E

A second outer loop runs the same inner structure with i increasing. That rebuilds the upper rows in reverse order so the pyramid completes without duplicating the widest E border twice.

Up
4

Nine symbol rows for five letters

Each printed line contains nine letter tokens (plus spaces from printf(" ")). You get 2 × 5 - 1 = 9 text rows: five steps down to the A floor, then four steps back up to the outer E frame.

9
=

Symmetry

The fifth and sixth rows differ only in the center run A vs B.

2

Variation — User Input

rows is the span from 'A' to endChar; lower loop i from startChar + 1 to k.

c
#include <stdio.h>

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

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

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

    for (i = k; i >= startChar; --i) {
        for (j = k; j >= startChar; --j) {
            if (j > i) {
                printf("%c ", j);
            } else {
                printf("%c ", i);
            }
        }
        for (j = startChar + 1; j <= k; ++j) {
            if (j > i) {
                printf("%c ", j);
            } else {
                printf("%c ", i);
            }
        }
        printf("\n");
    }

    for (i = startChar + 1; i <= k; ++i) {
        for (j = k; j >= startChar; --j) {
            if (j > i) {
                printf("%c ", j);
            } else {
                printf("%c ", i);
            }
        }
        for (j = startChar + 1; j <= k; ++j) {
            if (j > i) {
                printf("%c ", j);
            } else {
                printf("%c ", i);
            }
        }
        printf("\n");
    }

    return 0;
}

💡 Tips for Enhancement

Try These

  • Extract one row into a function to avoid duplicating the two inner loops
  • Hollow variant: print the shell letters only at the true border
  • Shrink width with %c only if you drop the trailing space

Avoid

  • Starting the second phase at 'A' (reprints the center row)
  • Forgetting that rows is the span from 'A' to the peak letter (total printed rows are 2 × rows - 1), not a single-phase row count

Key Takeaways

1

Program 29 = program 28 row logic extended with a return phase (down phase + up phase) for the full pyramid.

2

Second phase starts at 'B' to skip the duplicate A center line.

3

Total rows = 2 × rows - 1 when rows counts AendChar.

4

O(n²) characters for alphabet span n.

❓ Frequently Asked Questions

The step direction of i reverses at the center. Splitting the phases matches how people describe “upper half” and “lower half” and keeps the B start explicit.
Yes for this fixed case: nine rows with nine letter outputs each. In general, for n letters from A, you have 2n - 1 rows and 2n - 1 outputs per row, so (2n - 1)² letter prints.
Yes: map r to i with i = k - r for r in the first half and a symmetric map below the center. Two loops are easier to read next to program 28.
O(n²) for span n from A to the peak letter.

Explore More C Alphabet Patterns!

Composing a known row routine twice with a shifted range is a simple way to close the reverse centered pyramid.

All Alphabet Patterns →
Did you know?

For n letters from A, you print 2n - 1 rows and (2n - 1)² letter prints in the reference layout.

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