Symmetric Number Pattern with Asterisk Center in C

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

What You’ll Learn

How to print a symmetric number pattern where the center is filled with asterisks. As you go down the rows, the number range shrinks and the asterisk block expands.

This is a great pattern to practice splitting a row into three parts: left numbers, center stars, and right numbers.

⭐ Pattern Output

For rows = 5, the pattern looks like this:

Output
1234554321
1234**4321
123****321
12******21
1********1
1

Complete C Program

The first loop prints left numbers, the second prints center stars, and the third prints the mirrored right numbers.

c
#include <stdio.h>

int main() {
    int rows = 5;
    int i, j, k;

    for (i = 1; i <= rows; ++i) {
        for (j = 1; j <= rows - i + 1; ++j) {
            printf("%d", j);
        }
        for (k = 1; k <= 2 * (i - 1); ++k) {
            printf("*");
        }
        for (j = rows - i + 1; j >= 1; --j) {
            printf("%d", j);
        }
        printf("\n");
    }

    return 0;
}

🧠 How It Works

1

Outer loop controls rows

for (i = 1; i <= rows; ++i) prints one full line each time.

Row control
2

Left side numbers

Print ascending digits from 1 to rows - i + 1.

Left
3

Center stars

Print 2 * (i - 1) asterisks, which grows by 2 each row.

Center
4

Right side numbers (mirror)

Print descending digits from rows - i + 1 down to 1.

Right
=

A clean symmetric split

Each row has a mirrored number section and a centered star section. Total output per row is proportional to rows, so overall time complexity is O(n²).

2

Variation — User Input Version

Let the user choose the number of rows:

c
#include <stdio.h>

int main() {
    int rows;
    int i, j, k;

    printf("Enter the number of rows: ");
    scanf("%d", &rows);

    for (i = 1; i <= rows; ++i) {
        for (j = 1; j <= rows - i + 1; ++j) {
            printf("%d", j);
        }
        for (k = 1; k <= 2 * (i - 1); ++k) {
            printf("*");
        }
        for (j = rows - i + 1; j >= 1; --j) {
            printf("%d", j);
        }
        printf("\n");
    }

    return 0;
}

💡 Tips for Enhancement

Try These

  • Use a different center character (like # or -)
  • Add spaces between numbers for readability
  • Change the max number by using a different rows value
  • Create a hollow center by printing spaces instead of stars
  • Reverse it to start with stars and grow numbers

Avoid

  • Mixing up loop bounds (it breaks symmetry)
  • Forgetting the center star count formula 2*(i-1)
  • Skipping the newline after each row
  • Printing without spacing when using 2-digit numbers
  • Not validating input if rows can be negative

Key Takeaways

1

Split each row into three parts: left numbers, center stars, right numbers.

2

The number section shrinks while the center star section grows.

3

The pattern stays symmetric by mirroring loop limits.

4

Time complexity grows like O(n²) for n rows.

❓ Frequently Asked Questions

The third loop prints numbers in reverse to mirror the left side, giving perfect symmetry around the center.
Row i prints 2*(i-1) stars: 0, 2, 4, 6, 8…
Yes. Replace printf(\"*\") with your preferred character.
O(n²) for n rows because each row prints a number of characters proportional to n.

Explore More C Number Patterns!

Keep going with patterns that combine symmetry and multi-part rows.

All Number Patterns →
Did you know?

Many symmetric patterns can be built by printing a left part, a middle filler, and then the mirror of the left part. Once you master that split, you can build diamonds, hourglasses, and hollow shapes easily.

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