Number pattern 40 in C

Write a C program to print the given number pattern using loop. How to print the given number pattern using loop in C programming. Logic to print the given number pattern using C program.



Input N: 5


Required knowledge

Basic C programming, Loop

Logic to print the given pattern

On first look the pattern may seem little difficult to print out. Lets make things little easier and dissect the given pattern in two internal parts.

Between these two patterns spaces are printed in decreasing order i.e first row contains 8, second row contains 6 spaces and so on last row contains 0 spaces. Loop formation to print spaces will be for(j=i*2; j<N*2; j++).
Loop to print the above two pattern will be similar and simple. It has also been discussed in one of my earlier post. Lets combine everything in single program.

Program to print the given pattern

 * C program to print the given number pattern

#include <stdio.h>

int main()
    int i, j, N;

    printf("Enter rows: ");
    scanf("%d", &N);

    for(i=1; i<=N; i++)
        // Prints first part of pattern
        for(j=1; j<=i; j++)
            printf("%d", j);

        // Prints spaces between two parts
        for(j=i*2; j<N*2; j++)
            printf(" ");

        // Prints second part of the pattern
        for(j=i; j>=1; j--)
            printf("%d", j);


    return 0;


Enter rows: 5
1        1
12      21
123    321
1234  4321

Happy coding 😉

About Pankaj

Pankaj Prakash is the founder, editor and blogger at Codeforwin. He loves to learn new techs and write programming articles especially for beginners. He works at Vasudhaika Software Sols. as a Software Design Engineer and manages Codeforwin. In short Pankaj is Web developer, Blogger, Learner, Tech and Music lover.

Follow on: Twitter | Google | or

Comments and discussion
Have a doubt, write here. I will help my best.
Before commenting you must escape your source code before commenting. Paste your source code inside
<pre><code> ----Your Source Code---- </code></pre>