Number pattern 36 in C

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

Required knowledge

Basic C programming, Loop

Logic to print given pattern

Before I discuss the logic to print the given pattern I recommend you to have a careful eye on to the pattern. Following observations can be made about the pattern.

  1. It contains of N rows (where N is the total rows to be printed).
  2. Each row contains exactly double column as in previous row. And the first row contains 1 column.
  3. As per each column contains an integer from 1 to 9 in increasing order. When the number count reaches 10 it restarts to 1.

Below is the program that converts the above logic to computer code to print the given pattern.

Program to print the given pattern

 * C program to print the given number pattern

#include <stdio.h>

int main()
    int i, j, N, colCount, value;

    colCount = 1;
    value = 1;

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

    for(i=1; i<=N; i++)
        for(j=1; j<=colCount; j++)
            if(value == 10)
                value = 1; // Restart at 10

            printf("%d ", value);



        // Increase the total number of columns by 2
        colCount *= 2;

    return 0;


Enter rows: 5
2 3
4 5 6 7
8 9 1 2 3 4 5 6
7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4

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>