Symmetric Decreasing Alphabet Square in C++

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

What You’ll Learn

This pattern is built row by row. The outer letter stays high on the borders (E), while the center drops down to A.

We create symmetry by printing a left half (E down to A) and then a mirrored right half (B up to E).

⭐ Pattern Output

Output for 5 rows (a space after each letter):

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

C++ Program (Reference Logic)

Two symmetric scans per row with the same j > i check.

C++
#include <iostream>
using namespace std;

int main() {
    int i, j;
    int k = 69;

    for (i = k; i >= 65; i--) {
        for (j = k; j >= 65; j--) {
            if (j > i) cout << char(j) << " ";
            else cout << char(i) << " ";
        }
        for (j = 66; j <= k; j++) {
            if (j > i) cout << char(j) << " ";
            else cout << char(i) << " ";
        }
        cout << "\n";
    }

    return 0;
}

🧠 How It Works

1

Outer i

Acts like the “floor” letter for the row: E, then D, then C, B, A.

Floor
2

Left scan E..A

If j > i, print j (outer shell). Otherwise print i (interior fill).

Shell
3

Right scan B..E

Mirror the same rule. Starting at B prevents printing A twice in the middle.

Mirror
4

Output shape and cost

Each row runs two sweeps across the letter range and prints a space after every character, so width grows linearly with the alphabet span. For n letters from A, that is O(n²) writes in the nested-loop form shown.

O(n²)
=

Symmetry

Each row is mirrored around the center column.

2

Variation — User Input

Choose the number of rows. The top letter becomes endChar = 'A' + rows - 1, and row width becomes 2*(endChar - 'A') + 1.

C++
#include <iostream>
using namespace std;

int main() {
    int rows;
    cout << "Enter the number of rows: ";
    cin >> rows;

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

    for (char i = endChar; i >= startChar; --i) {
        for (char j = endChar; j >= startChar; --j) {
            cout << (j > i ? j : i) << ' ';
        }
        for (char j = char(startChar + 1); j <= endChar; ++j) {
            cout << (j > i ? j : i) << ' ';
        }
        cout << "\n";
    }

    return 0;
}

💡 Tips for Enhancement

Try These

  • Remove the trailing space after each letter if you want a compact block
  • Try larger sizes (up to rows <= 26) and observe how width grows as 2n - 1
  • Build the same row using a single loop over column index and a mirrored letter index

Avoid

  • Starting the second half at A (you would duplicate the center letter)
  • Forgetting that output width scales with 2n - 1 (console lines get long quickly)

Key Takeaways

1

Reuse one rule: print j when j > i, else print i.

2

Two passes (down then up) make the row symmetric.

3

Width for rows letters is 2*rows - 1 cells (plus spaces if you print them).

4

O(n²) output for n rows.

❓ Frequently Asked Questions

The left half already printed A in the middle. Starting the right half at B avoids printing A twice.
For rows = 5 letters (A..E), there are 5 lines and 9 printed cells per line, forming a symmetric block (often called a square/rangoli style pattern in console tutorials).
O(n²) for n letters because each row prints O(n) cells and there are O(n) rows.

Explore More C++ Alphabet Patterns!

Once you understand the j > i rule, you can generate many “shell” and “rangoli” style patterns.

All Alphabet Patterns →
Did you know?

The bottom row spells the full palindrome E D C B A B C D E: the first half 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