Symmetric Number Pattern with Asterisk Center in C

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:
1234554321
1234**4321
123****321
12******21
1********1Complete C Program
The first loop prints left numbers, the second prints center stars, and the third prints the mirrored right numbers.
#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
Outer loop controls rows
for (i = 1; i <= rows; ++i) prints one full line each time.
Left side numbers
Print ascending digits from 1 to rows - i + 1.
Center stars
Print 2 * (i - 1) asterisks, which grows by 2 each row.
Right side numbers (mirror)
Print descending digits from rows - i + 1 down to 1.
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²).
Variation — User Input Version
Let the user choose the number of rows:
#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
rowsvalue - 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
Split each row into three parts: left numbers, center stars, right numbers.
The number section shrinks while the center star section grows.
The pattern stays symmetric by mirroring loop limits.
Time complexity grows like O(n²) for n rows.
❓ Frequently Asked Questions
i prints 2*(i-1) stars: 0, 2, 4, 6, 8…printf(\"*\") with your preferred character.Explore More C Number Patterns!
Keep going with patterns that combine symmetry and multi-part rows.
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.
12 people found this page helpful
