Symmetric Alphabet, Star Center

What You’ll Learn
Build rows that read the same forwards and backwards on the letters, with * filling the gap in the middle as the row shortens.
Outer loop runs 5 down to 1. See also C star patterns for more * shapes.
⭐ Pattern Output
For n = 5:
ABCDEEDCBA
ABCD**DCBA
ABC****CBA
AB******BA
A********AComplete C Program (Five Rows)
To generalize, introduce int n = rows; and use n wherever 5 appears (outer start value and 2 * (n - i)).
#include <stdio.h>
int main() {
int i, j;
char ch;
for (i = 5; i >= 1; --i) {
ch = 'A';
for (j = 1; j <= i; ++j) {
printf("%c", ch++);
}
for (j = 1; j <= 2 * (5 - i); ++j) {
printf("*");
}
ch--;
for (j = 1; j <= i; ++j) {
printf("%c", ch--);
}
printf("\n");
}
return 0;
}🧠 How It Works
Outer i = n .. 1
Each row is built from the current width i down to 1, so the pattern starts wide and tapers. At the top of the body you reset ch = 'A' so every row begins its left ramp from A.
Left half with ch++
The first inner loop prints i ascending letters starting at A. For i = 5 you get ABCDE; for i = 4 you get ABCD, and so on.
Star block 2*(n-i)
A separate loop prints * in the gap where a full mirror would meet the left half. When i = n the count is zero (no stars on the widest line); when i shrinks, the star run grows.
ch--, then the right half
After the left segment, ch sits on the letter that must repeat at the mirror. One ch-- lines it up with the descending run. The final inner loop prints i letters stepping down so the row reads as a palindrome around the star block.
Fixed width per row
Letters on the left plus stars plus letters on the right: i + 2(n-i) + i = 2n. For n = 5 every line has 10 symbols. Each row does work proportional to n, for n rows → O(n²).
Variation — User Input
Same formulas with rows instead of 5.
#include <stdio.h>
int main() {
int rows, i, j;
char ch;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = rows; i >= 1; --i) {
ch = 'A';
for (j = 1; j <= i; ++j) {
printf("%c", ch++);
}
for (j = 1; j <= 2 * (rows - i); ++j) {
printf("*");
}
ch--;
for (j = 1; j <= i; ++j) {
printf("%c", ch--);
}
printf("\n");
}
return 0;
}💡 Tips for Enhancement
Try These
- Swap
*for spaces or.for a softer look - Trace one row on paper: track
chafter left loop, afterch--, after each right print - Ensure
rowsis positive and small enough thatchstays insideA–Z
Avoid
- Omitting the single
ch--after stars (right side starts one letter too late) - Using
2 * ifor stars instead of2 * (n - i)(center width inverts)
Key Takeaways
Three inner passes: ascending letters, stars, descending letters.
ch-- bridges the gap between “one past last left letter” and “first right letter.”
Each full row length is 2n characters when the peak row has n letters.
Overall time O(n²) for n rows.
❓ Frequently Asked Questions
i == n, 2 * (n - i) = 0. The two halves meet directly: ABCDE + EDCBA.i + 2(5-i) + i = 10. For general n, each row prints exactly 2n characters.rows >= 1.Explore More C Alphabet Patterns!
Mixing characters and stars is the same idea as hollow or diamond star programs — split the row into zones.
The middle letter of the first row appears twice in a row (EE in ABCDEEDCBA) because the left block ends at E and the right block starts at E after ch--.
12 people found this page helpful
