Symmetric Decreasing Alphabet Square in C++

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):
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 EC++ Program (Reference Logic)
Two symmetric scans per row with the same j > i check.
#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
Outer i
Acts like the “floor” letter for the row: E, then D, then C, B, A.
Left scan E..A
If j > i, print j (outer shell). Otherwise print i (interior fill).
Right scan B..E
Mirror the same rule. Starting at B prevents printing A twice in the middle.
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.
Symmetry
Each row is mirrored around the center column.
Variation — User Input
Choose the number of rows. The top letter becomes endChar = 'A' + rows - 1, and row width becomes 2*(endChar - 'A') + 1.
#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 as2n - 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
Reuse one rule: print j when j > i, else print i.
Two passes (down then up) make the row symmetric.
Width for rows letters is 2*rows - 1 cells (plus spaces if you print them).
O(n²) output for n rows.
❓ Frequently Asked Questions
A in the middle. Starting the right half at B avoids printing A twice.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).Explore More C++ Alphabet Patterns!
Once you understand the j > i rule, you can generate many “shell” and “rangoli” style patterns.
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.
12 people found this page helpful
