Program to print the given number pattern
54321
4321
321
21
1

C Programming Language Loop control in C Language (Article) Loop control in C Language (Program)

16381

Program:

/**
 * C program to print number pattern
 * www.rummanansari.com
 */

#include <stdio.h>

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

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

    for(i=N; i>=1; i--)
    {
        // Logic to print numbers
        for(j=i; j>=1; j--)
        {
            printf("%d", j);
        }

        printf("\n");
    }

    return 0;
}

Output:

Output
Enter N: 5
54321
4321
321
21
1

Explanation:

Logic to print the given number pattern

 

54321
4321
321
21
1

 

The above pattern consists of N rows (where N is the total rows to be printed). To since the pattern is in descending order hence, to make things easier we will iterate through rows from N-1 instead of 1-N so now the first row is row5, second row is row4 and last row is row1. Each row contains exactly i columns (where i is the current row number).
The step-by-step descriptive logic of the pattern is:

  1. To iterate through rows, run an outer loop from N to 1 in decreasing order.
  2. To print the columns, run an inner loop from i to 1 in decreasing order. Inside this loop print the value of j (where j is the current column number).

This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.