Symmetric Decreasing Alphabet Square in C

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

What You’ll Learn

Two passes per row share the same rule: print the larger of j and i when j > i, else print i. That fills a square whose “floor” drops row by row until A sits in the center of the last line, flanked by B C D E.

Compare program 24 (palindrome triangle) and program 27 (right-aligned growing rows).

⭐ Pattern Output

Five rows, nine letters per row (with a space after each %c in the program):

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
1

Complete C Program ('A''E')

char k = 'E'; outer i from k down to 'A'.

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");
    }

    return 0;
}

🧠 How It Works

1

i = row floor

Starts at E; each row the plateau letter drops until A on the last line.

Down
2

Left half k ↓ A

When j > i, the visible letter follows j (outer shell); otherwise the row floor i fills the interior.

j>i
3

Right half B ↑ k

Same test; starting at B skips a second A after the middle A from the first loop.

Mirror
4

%c

Trailing space after each letter matches the reference output spacing.

Space
=

Symmetry

Each row reads the same left-to-right as right-to-left.

2

Variation — User Input

endChar = (char)('A' + rows - 1) assigns k; second loop starts at startChar + 1.

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");
    }

    return 0;
}

💡 Tips for Enhancement

Try These

  • Remove the trailing space in printf and rely on %2c if you want grid alignment
  • Try a larger endChar and confirm the row width 2(k - A) + 1
  • Draw the same shape with a single loop over column index and mirror math

Avoid

  • Starting the second loop at 'A' (would print A twice on the last row)
  • Confusing row index i with column index j when tracing j > i

Key Takeaways

1

The same if (j > i) rule is reused in both inner loops for a consistent shell and core.

2

Second loop begins at B so the center A appears only once.

3

Row width is 2 × (k - 'A') + 1 symbols (nine for AE).

4

O(n²) output for n letters from A to the top row letter.

❓ Frequently Asked Questions

For columns whose letter index j is still above the current floor i, you show the “wall” letter j. At and below the floor you show i.
No. Nine prints per row times five rows is 45 letter prints; big-O is still quadratic because row length scales with n.
Yes, by mapping column positions to a descending then ascending j with a single midpoint rule; the two-loop version matches the reference and keeps the mirror explicit.
O(n²) for n rows over an n-wide alphabet span.

Explore More C Alphabet Patterns!

Reusing one comparison in two sweeps is an easy way to enforce symmetry without manual string reversal.

All Alphabet Patterns →
Did you know?

The bottom row spells the full palindrome E D C B A B C D E: the first loop contributes down to A, the second continues upward from B.

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