Number pattern 43 in C

Write a C program to print the given number pattern using for 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 number pattern

Logic to print the given pattern might look complicated at first sight. Take your time and think about any special pattern about the given number series. You might notice following interesting things about the pattern.

  1. It contains total N rows (where N is the total number of rows to be printed).
  2. Each row contains exactly i columns (where i is the current row number).
  3. If you notice about the integers printed in each column. They are in increasing order with increasing difference. The difference between first two integers is 1 followed by a difference of 2, 3, 4, 5 and so on.

Based on the above observations lets code down solution of the given pattern.

Program to print the given number pattern

 * C program to print the given number pattern

#include <stdio.h>

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

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

    diff = 1;
    value = 1;

    for(i=1; i<=N; i++)
        for(j=1; j<=i; j++)
            printf("%-3d", value);

            value += diff; // Computes the next value to be printed
            diff++;        // Increments the difference


    return 0;


Enter rows: 5
2  4
7  11 16
22 29 37 46
56 67 79 92 106

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>