Palindromic Pattern with 0 at Center in C

What You’ll Learn
How to print a palindromic number pattern where every row has a 0 in the middle. Numbers rise toward 9, then mirror back after the 0.
This pattern is built from three parts per row: ascending numbers, the center 0, then descending numbers.
⭐ Pattern Output
For a maximum value of 10 (producing 10 rows), the pattern looks like this:
0
909
89098
7890987
678909876
56789098765
4567890987654
345678909876543
23456789098765432
1234567890987654321Complete C Program
We print ascending values up to 9, print a center 0, then print descending values back to the row’s start.
#include <stdio.h>
int main() {
int i, j, k;
for (i = 10; i >= 1; i--) {
for (j = i; j < 10; j++) {
printf("%d", j);
}
printf("0");
for (k = 9; k >= i; k--) {
printf("%d", k);
}
printf("\n");
}
return 0;
}🧠 How It Works
Outer loop controls the start value
for (i = 10; i >= 1; i--) decides where each row starts (from 10 down to 1).
Print ascending numbers
for (j = i; j < 10; j++) prints i, i+1, ... up to 9.
Print the center 0
printf("0") places a single 0 in the middle of each row.
Print descending numbers
for (k = 9; k >= i; k--) prints 9 down to i to mirror the left side.
Palindromic rows with 0 center
The right side mirrors the left side around the center 0.
Variation — User Input Version
Read the maximum value from the user and generate the same palindromic pattern.
#include <stdio.h>
int main() {
int max;
printf("Enter the maximum value: ");
scanf("%d", &max);
int i, j, k;
for (i = max; i >= 1; i--) {
for (j = i; j < max; j++) {
printf("%d", j);
}
printf("0");
for (k = max - 1; k >= i; k--) {
printf("%d", k);
}
printf("\n");
}
return 0;
}💡 Tips for Enhancement
Try These
- Replace
0with a custom center character (e.g.,*orX) - Add spaces between numbers for readability
- Limit the maximum to 9 if you want single digits only
- Print the pattern in ascending row order instead of descending
- Center-align each row by printing leading spaces
Avoid
- Forgetting to print the center 0 (breaks the pattern symmetry)
- Using an inconsistent range between the left and right sides
- Not validating user input (negative/zero max)
- Printing extra characters after each row
Key Takeaways
Each row is built from ascending numbers, a center 0, and descending numbers.
The right side mirrors the left side, so each row is a palindrome.
Nested loops make this pattern straightforward to generate.
Changing the center character creates many interesting variations.
❓ Frequently Asked Questions
0. The sequence increases toward 9, prints 0, then decreases back to the start value—so it reads the same both ways.printf("0") with something like printf("*") or printf("X").Explore More C Number Patterns!
Try more palindromic and symmetric patterns to level up your nested loop skills.
Patterns with a center character (like 0) are a simple way to learn how to build symmetry by printing a left part, a center, and then a mirrored right part.
12 people found this page helpful
