Diamond Number Pattern with Decreasing Values in C

Beginner
⏱️ 6 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Conditions + Loops

What You’ll Learn

How to print a symmetric number pattern where values decrease from the edges toward the center. We’ll use two inner loops to mirror left and right halves, and a condition to decide whether to print j (outer) or i (inner).

⭐ Pattern Output

For k = 5, the pattern looks like this:

Output
5 5 5 5 5
5 4 4 4 5
5 4 3 4 5
5 4 4 4 5
5 5 5 5 5
1

Complete C Program

We print a left half (j = k..1) and a right half (j = 2..k) to keep the output symmetric.

c
#include <stdio.h>

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

    for (i = k; i >= 1; i--) {
        for (j = k; j >= 1; j--) {
            if (j > i)
                printf("%d ", j);
            else
                printf("%d ", i);
        }

        for (j = 2; j <= k; j++) {
            if (j > i)
                printf("%d ", j);
            else
                printf("%d ", i);
        }

        printf("\n");
    }

    return 0;
}

🧠 How It Works

1

Choose the maximum value (k)

k is the outer value and controls the size of the pattern.

Setup
2

Outer loop controls rows

for (i = k; i >= 1; i--) moves toward the center as i decreases.

Rows
3

Left half (mirror start)

j = k..1 prints the left side. The condition selects the larger outer values.

Left
4

Right half (mirror finish)

j = 2..k prints the right side to keep symmetry.

Right
=

Decreasing center values

The center becomes smaller because when j <= i we print i instead of j.

2

Variation — User Input Version

Read k from the user so you can print different sizes.

c
#include <stdio.h>

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

    printf("Enter the maximum value (pattern size): ");
    scanf("%d", &k);

    for (i = k; i >= 1; i--) {
        for (j = k; j >= 1; j--) {
            if (j > i)
                printf("%d ", j);
            else
                printf("%d ", i);
        }

        for (j = 2; j <= k; j++) {
            if (j > i)
                printf("%d ", j);
            else
                printf("%d ", i);
        }

        printf("\n");
    }

    return 0;
}

💡 Tips for Enhancement

Try These

  • Let the user choose k (shown above)
  • Remove spaces in printf for a tighter look
  • Reverse the comparison to create an increasing-from-center variant
  • Print only the border values to make a hollow version

Avoid

  • Forgetting the second loop (j = 2..k), which breaks symmetry
  • Using k < 1 without validating input

Key Takeaways

1

Two inner loops mirror the left and right halves.

2

The condition j > i chooses whether to print the outer value (j) or the inner value (i).

3

Increasing k increases the size of the pattern.

4

The runtime grows roughly as O(k²).

❓ Frequently Asked Questions

Printing j keeps the outer border large; printing i creates smaller values toward the center.
Increase k (or use the input version). For example, k = 7 prints a larger pattern.
The left half decreases and the right half mirrors it, producing a symmetric shape with smaller values at the center.
O(k²), since there are k rows and roughly 2k-1 prints per row.

Explore More C Number Patterns!

Master loops and conditions with more practice patterns.

All Number Patterns →
Did you know?

This pattern prints 2k - 1 values per row. For k = 5, that’s 9 values per row across 5 rows.

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