Palindromic Pattern with 0 at Center in C

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

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:

Output
0
909
89098
7890987
678909876
56789098765
4567890987654
345678909876543
23456789098765432
1234567890987654321
1

Complete C Program

We print ascending values up to 9, print a center 0, then print descending values back to the row’s start.

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

1

Outer loop controls the start value

for (i = 10; i >= 1; i--) decides where each row starts (from 10 down to 1).

Row control
2

Print ascending numbers

for (j = i; j < 10; j++) prints i, i+1, ... up to 9.

Ascending
3

Print the center 0

printf("0") places a single 0 in the middle of each row.

Center
4

Print descending numbers

for (k = 9; k >= i; k--) prints 9 down to i to mirror the left side.

Descending
=

Palindromic rows with 0 center

The right side mirrors the left side around the center 0.

2

Variation — User Input Version

Read the maximum value from the user and generate the same palindromic pattern.

c
#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 0 with a custom center character (e.g., * or X)
  • 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

1

Each row is built from ascending numbers, a center 0, and descending numbers.

2

The right side mirrors the left side, so each row is a palindrome.

3

Nested loops make this pattern straightforward to generate.

4

Changing the center character creates many interesting variations.

❓ Frequently Asked Questions

Every row is symmetric around a single 0. The sequence increases toward 9, prints 0, then decreases back to the start value—so it reads the same both ways.
The ascending part builds the left side, the 0 is the center, and the descending part mirrors the left side to create the palindrome.
Yes. Replace printf("0") with something like printf("*") or printf("X").
O(n²) where n is the maximum value, because each row prints a growing sequence using nested loops.

Explore More C Number Patterns!

Try more palindromic and symmetric patterns to level up your nested loop skills.

All Number Patterns →
Did you know?

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.

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