A symmetric alphabet with star center prints left letters A..i, an even star gap, then mirrored letters i..A. Letter halves shrink while stars grow, so every row keeps the same width 2n.
Remember
Rule: left A..i + 2*(top-i) stars + right i..A
ABCDEEDCBA
ABCD**DCBA
ABC****CBA
AB******BA
A********A ← 5 rows (top = E)
On the first row the star count is 0, so the middle letter appears twice (EE in ABCDEEDCBA). That is intentional — left ends at i and right starts at i. Compare with Program 14 (odd-length prefixes) and Program 16 (centered pyramid).
Approach
How to Solve It
Count down the letter-half end, then print three parts in order: left, stars, right.
Method
Idea
Best for
Three nested loops
Left letters, star loop, right letters
Learning, interviews, exams
string(stars, '*')
Same letters; one call for the star gap
Cleaner demos once the shape is clear
Pseudocode
Pseudocode
top = 'A' + rows - 1
for i from top down to 'A':
for j from 'A' to i:
print j (no newline)
stars = 2 * (top - i)
print stars copies of '*'
for m from i down to 'A':
print m (no newline)
print newline
Cheat sheet
Goal
Pattern
Pick the letter-half end
for (char i = top; i >= 'A'; i--)
Left ascending
for (char j = 'A'; j <= i; j++) cout << j;
Star gap
int stars = 2 * (top - i);
Right descending
for (char m = i; m >= 'A'; m--) cout << m;
One-call stars
cout << string(stars, '*');
End the row
cout << "\n";
A–Z-safe height
Clamp rows to 1–26
Printing Letters vs Starting a New Line
API
Effect
Use for
cout << ch / '*'
Stays on the same line
Each letter and each star
cout << "\n"
Ends the current line
After left + stars + right
Print characters without a newline, then end the row once.
Try it
Live Preview
Change the row count and the symmetric star-center pattern updates instantly — including top letter and width.
Whole numbers from 1 to 13. Top letter is A + rows - 1; each row is width 2 × rows.
1. Same left and right. Letter halves are unchanged from Example 1.
2. One-call gap.string(stars, '*') creates the whole even star gap at once.
3. When to use which. Keep the explicit star loop for exams that ask you to show all bounds; use the string constructor for cleaner demos.
Edge Cases & Pitfalls
Check these before calling the solution done.
Order
Wrong part order
Always print left, then stars, then right. Swapping sides breaks the mirror.
stars = top - i
Odd gap
Forget the 2 * and the gap is too small — width will not stay 2n.
Right from i-1
Missing middle twin
Starting the right half at i - 1 removes the doubled center letter. Only do that if the problem asks for it.
cout "\n" early
Broken row
Call cout << "\n" only after all three parts. Inside any inner loop, the row splits.
rows = 1
Single AA
Output is AA (left A + right A, zero stars) — a good sanity check.
Past Z
Clamp to 26
More than 26 rows walks past Z. Clamp or reject the input.
Analysis
Time and Space Complexity
Program
Time
Extra space
Three-loop form (Examples 1–2)
O(n²)
O(1)
string gap (Example 3)
O(n²)
O(n) for the temporary star string
Each of n rows prints 2n characters (letters + stars), so total work is quadratic in the row count.
Remember
Key Takeaways
Three parts: left A..i, even star gap, right i..A.
Even stars:stars = 2 * (top - i) keeps width 2n.
Doubled center: first row has zero stars, so the middle letter appears twice.
Complexity:O(n²) time; loops use O(1) extra space.
One line: for each end letter counting down, print A..i, then 2*(top-i) stars, then i..A.
Frequently Asked Questions
The left half prints A..E, and the right half prints E..A. When there are zero stars on the first row, E appears as the last character of the left half and the first character of the right half.
Stars per row are 2*(top - end). For top=E: 0, 2, 4, 6, 8 stars as end goes E, D, C, B, A.
Because it is computed as 2*(top - i), which is always a multiple of 2.
Yes. You can start the right half from (char)(i - 1) instead of i when there are zero stars, so the first row becomes ABCDEDCBA.
cout << ch stays on the same line. cout << "\n" ends the current line. Letters and stars use cout; the row break uses cout << "\n" after all three parts.
O(n²) for n rows. Each row prints a total of 2n characters (letters + stars), repeated across n rows.
Yes. cout << string(stars, '*') prints the whole gap in one call. Nested star loops are fine for learning; the string constructor is a handy shortcut later.
After cin >> rows, check failure with if (!(cin >> rows)). Clamp rows between 1 and 26 so you stay within A–Z.
🤔
Did you know?
Each row is: ascending letters from A to the row end, then 2*(top - end) stars, then descending letters back to A. The middle letter appears twice when star count is 0, producing ABCDEEDCBA on the first row. Total width stays constant at 2n characters per row.