Complete Diamond Pattern with Decreasing Values in C

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

What You’ll Learn

How to print a complete symmetric diamond-style number pattern where values decrease from the edges (k) to the center (1) and then increase back. We’ll build the upper and lower halves separately to keep the output symmetric without duplicating the center row.

⭐ Pattern Output

For k = 5, the pattern looks like this:

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

Complete C Program

The first part prints i = k..1. The second part prints i = 2..k to mirror the top and avoid repeating the center row.

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");
    }

    for (i = 2; i <= k; 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

Set k (outer value)

k is the maximum edge value and controls size.

Setup
2

Upper half: i = k..1

This part moves toward the center value (1).

Upper
3

Symmetry per row

Each row is made symmetric using two inner loops: left half (j=k..1) and right half (j=2..k).

Mirror
4

Choose j or i

If j > i, print j (outer). Otherwise print i (inner).

Condition
5

Lower half: i = 2..k

Start at 2 to avoid printing the center row twice, then mirror the top.

Lower
=

Complete decreasing diamond

Values decrease to the center, then increase back due to the two-part loop structure.

2

Variation — User Input Version

Read k from the user to 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");
    }

    for (i = 2; i <= k; 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 trailing spaces by adjusting printing logic
  • Reverse the comparison to make values increase toward the center
  • Print only the border values for a hollow variant

Avoid

  • Starting the lower half at i = 1 (would duplicate the center row)
  • Using k < 1 without validating input

Key Takeaways

1

A complete diamond is built using an upper half and a lower half.

2

Each row is mirrored using two inner loops (left and right halves).

3

The condition j > i controls whether an outer or inner value is printed.

4

The runtime grows roughly as O(k²).

❓ Frequently Asked Questions

Because i=1 is already printed as the center row in the upper half. Starting from 2 avoids duplication.
It has 2k - 1 rows. For k=5, that’s 9 rows.
Yes. Remove the space in printf("%d ", ...) or print spaces conditionally.
O(k²) because the grid is roughly (2k-1) × (2k-1).

Explore More C Number Patterns!

Keep practicing nested loops and conditions with new patterns.

All Number Patterns →
Did you know?

A full pattern of size k has 2k-1 rows and 2k-1 values per row. For k=5, that’s a 9×9 grid.

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