Symmetric Alphabet, Star Center

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

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:

Output
ABCDEEDCBA
ABCD**DCBA
ABC****CBA
AB******BA
A********A
1

Complete C Program (Five Rows)

To generalize, introduce int n = rows; and use n wherever 5 appears (outer start value and 2 * (n - i)).

c
#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

1

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.

Rows
2

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.

Up
3

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.

Center
4

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.

Down
=

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²).

2

Variation — User Input

Same formulas with rows instead of 5.

c
#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 ch after left loop, after ch--, after each right print
  • Ensure rows is positive and small enough that ch stays inside AZ

Avoid

  • Omitting the single ch-- after stars (right side starts one letter too late)
  • Using 2 * i for stars instead of 2 * (n - i) (center width inverts)

Key Takeaways

1

Three inner passes: ascending letters, stars, descending letters.

2

ch-- bridges the gap between “one past last left letter” and “first right letter.”

3

Each full row length is 2n characters when the peak row has n letters.

4

Overall time O(n²) for n rows.

❓ Frequently Asked Questions

When i == n, 2 * (n - i) = 0. The two halves meet directly: ABCDE + EDCBA.
Yes: i + 2(5-i) + i = 10. For general n, each row prints exactly 2n characters.
The outer loop does not run. In real programs, validate input so rows >= 1.
O(n²) for n rows.

Explore More C Alphabet Patterns!

Mixing characters and stars is the same idea as hollow or diamond star programs — split the row into zones.

All Alphabet Patterns →
Did you know?

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--.

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