Shape Rule
Layered square
Borders stay high; interiors drop toward A.

Stay symmetric by printing a left half (E down to A) and a mirrored right half (B up to E). Each cell follows the same rule: if j > i print the column letter; otherwise print the current row floor i. Compare Program 21 (diamond symmetry) and Program 24 (palindrome triangles). Includes a live preview, worked C examples, edge cases, and complexity.
Layered square
Borders stay high; interiors drop toward A.
Mirror
Left E..A, right B..E — A once in the center.
j > i
Print column letter or row floor letter.
2k+1
For A..E (k=4), every row has 9 letters.
Top letter
Pick a top letter (A–F) and draw the layers.
Complexity
n rows × O(n) cells each.
A symmetric decreasing alphabet square prints fixed-width rows whose outer letters stay high while the interior floor drops from the top letter down to A, mirrored left and right.
In C you solve it with an alphabet array, a descending row floor, and two column scans that share the same j > i choice rule.
It teaches mirrored scans, a shared cell rule, and how to keep a single center letter — skills that transfer to concentric squares and Program 29.
Drops E → A each row.
Left half + right half.
Border vs interior choice.
Right half starts at B.
In short: for each floor i from top down to A, scan left k..A and right B..k, printing j > i ? j : i, then call printf("\n").
Given a top letter (or fixed E), print a fixed-width symmetric square whose interior floor drops from the top letter down to A.
// Five rows (space after each letter; width 9)
// 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 | Item | Type | Description |
|---|---|---|
top / k | char / int | Top letter; k = top - 'A' (4 for E). Rows = k+1. |
| Printed output | text | Symmetric layers of width 2k+1 with a dropping floor. |
k = top - 'A'
for i from k down to 0: // row floor
for j from k down to 0: // left half
print (j > i ? letter[j] : letter[i]) + " "
for j from 1 to k: // right half (skip 0)
print (j > i ? letter[j] : letter[i]) + " "
print newline | Approach | Idea | Best for |
|---|---|---|
| Two mirrored scans | Left k..0 + right 1..k with j>i | Matching this classic sample |
| Distance from center | print letter by max(dx, dy) style | Concentric / diamond variants |
| Goal | Pattern |
|---|---|
| Top letter | char k = 'E'; (or from scanf) |
| Rows | for (i = k; i >= 'A'; --i) |
| Left half | for (j = k; j >= 'A'; --j) /* j>i ? j : i */ |
| Right half | for (j = 'B'; j <= k; ++j) /* same rule */ |
| Full diamond next | See Program 29 |
Same row — four roles that build the layered square.
leftDescending half through the center A
rightAscending mirror; skips duplicating A
floorBorder letter vs row-floor letter
breakEnds the row after both halves
Reach for this when teaching mirrored scans and shared cell rules for layered squares.
Step up from prefixes to concentric-style layers.
Practice one rule reused on both halves.
Same row logic, then mirror upward for a full diamond.
Map letters to array indexes and reuse them safely.
This is a console teaching pattern — not how you build modern app screens.
Key benefit: one shared j > i rule on mirrored halves is the cleanest way to build layered alphabet squares without special-casing the center.
Choose a top letter from A to F and draw the symmetric decreasing alphabet square in the browser.
Three complete C programs — fixed A–E, scanf top letter, and a shared print_cell helper. Click View Output to reveal sample console results.
Print five layered rows from E down to the A-center floor.
Two symmetric scans per row with the same j > i check, matching the reference logic.
#include <stdio.h>
int main() {
char k = 'E';
char i, j;
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;
} When i = 'C', columns where j > 'C' print E/D borders, and interior cells print C. The right half starts at 'B' so the center A is not duplicated on the last row.
Let the user pick the top letter (like E).
Works for A..top with the same symmetric square. Check scanf’s return value and require A–Z in real apps.
#include <stdio.h>
int main() {
char top, k, i, j;
printf("Enter top letter (like E): ");
scanf(" %c", &top);
k = top;
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;
} k = top scales both the floor loop and the two halves. Width becomes 2*(top-'A')+1 (5 letters for top = C).
Same shape with a shared print helper for both halves.
Often clearer to read: one function applies the floor rule so left and right loops stay thin.
#include <stdio.h>
void print_cell(char j, char i) {
if (j > i) {
printf("%c ", j);
} else {
printf("%c ", i);
}
}
int main() {
char k = 'E';
char i, j;
for (i = k; i >= 'A'; --i) {
for (j = k; j >= 'A'; --j) {
print_cell(j, i);
}
for (j = 'B'; j <= k; ++j) {
print_cell(j, i);
}
printf("\n");
}
return 0;
} print_cell owns the j > i rule once. Left and right loops only decide which columns to visit.
Set k to the top letter (like 'E'). Every printed cell is a letter from 'A' through k.
Row letter i runs from k down to 'A'. Smaller i means a deeper inner layer — think of i as the minimum letter allowed in that row.
For columns j = k..'A', choose with j > i ? j : i. Borders stay high; interiors drop to the row floor.
Scan j = 'B'..k. Starting at 'B' avoids printing the center A twice. Total columns: 2*(k-'A')+1 (9 for A–E).
Each row is a symmetric layer around the center. As i decreases, the minimum letter moves inward (E → D → C → B → A) — O(n²) time.
Trace each row floor and the resulting 9-letter line.
i | Floor letter | Printed row |
|---|---|---|
4 | E | E E E E E E E E E |
3 | D | E D D D D D D D E |
2 | C | E D C C C C C D E |
1 | B | E D C B B B C D E |
0 | A | E D C B A B C D E |
Width is always 2×4+1 = 9. The last row is the full palindrome around a single A.
Where this layered alphabet square shows up beyond the homework prompt.
Clearest demo of borders staying high while interiors drop.
Example: flip j > i to j >= i and watch layers shift.
Reuse one cell rule on left and right scans.
Example: start the right half at 0 and see a double A.
Practice k = top - 'A' with an alphabet array.
Example: scale from E to H without rewriting loops.
Factor the floor rule into one function (Example 3).
Example: reuse print_cell for Program 29 later.
Fixed width × n rows makes O(n²) easy to see.
Example: 5 rows × 9 cells = 45 prints.
Reuse this row logic, then mirror upward for a full diamond.
Example: continue to Program 29.
Pro Tip: say “left E..A, right B..E, print max of column and floor” before coding — that story prevents a duplicated center A.
Why this pattern earns a spot after simpler pyramids and rotations.
A broken mirror or wrong floor shows up immediately.
Both halves reuse the same j > i choice.
Change k and the whole square grows.
The same row logic becomes half of a full diamond.
Pro Tip: learn the inline ternary version first; extract print_cell once the floor rule feels automatic.
Small habits that keep layered alphabet squares clean.
Starting at 0 duplicates the center A.
Reuse j > i ? ('A' + j) : ('A' + i) on both halves.
Use k = top - 'A' so scaling stays automatic.
Require a single A–Z character; normalize case if needed.
The sample prints a space after every letter; trim if you need clean ends.
Pro Tip: if the last row shows ... A A B ..., the right half almost certainly started at j = 0.
Mistakes that commonly break symmetric decreasing alphabet squares.
Duplicates the center A.
→ Start the right scan at j = 1.
Using j >= i or swapping operands changes layer borders.
→ Keep j > i ? j : i.
Hard-coding k = 'E' while reading a different top letter breaks the square.
→ Set k from the chosen top letter.
scanfEmpty or non-letter input leaves top invalid.
→ Check scanf’s return value and require A–Z.
Running i from 0 to k prints layers in reverse order.
→ Descend i from k down to 0.
Check these inputs before calling the solution done.
Output is just A (right half empty).
5 rows × width 9 through the A center.
3 rows × width 5 (Example 2).
Normalize with char.toupper if needed.
Unchecked scanf fails silently — check the return value.
Replace alpha with 5..1 style indexes.
Try these variations to lock in the pattern.
j > i ? ('A' + j) : ('A' + i) builds borders and interiors together.2k + 1 (9 for A..E).Quick Takeaway: drop the floor from top to A, print left then right with the same j > i rule, and skip duplicating the center.
| Program | Time | Extra space |
|---|---|---|
| Inline / input (Examples 1–2) | O(n²) | O(1) (plus alphabet source) |
| Helper function (Example 3) | O(n²) | O(1) |
For n letters there are n rows and each row prints O(n) cells (width 2n-1), so total work is O(n²).
The symmetric decreasing alphabet square is a small nested-loop exercise with lasting payoff: mirrored halves, a shared floor rule, and a single center A. Master the classic E…A sample, then try user input and the helper rewrite.
Practice the three examples above, then continue to Program 29’s reverse centered alphabet pyramid.
Drop the floor, print left then right with j > i, start the right half at 1, then break the line.
j = 1j > i floor rule on both halvesk from the top letterscanf and require an A–Z top letterprintf("\n") inside either half loopPrint the symmetric decreasing alphabet square the beginner-friendly way.
Mirror + floor
Definitionj > i ? j : i
CodeStart at B
CodeEnds each row
I/OO(n²) time
AnalysisFix k at the top letter (E). Outer loop i goes from k down to A. Left half scans j = k..A; right half scans j = B..k so A appears once in the middle. Each position prints j when j > i, otherwise prints i.
Next up: reverse-centered alphabet pyramids / diamonds.
12 people found this page helpful