Home C Programming Language / Programs / Program to print the given number pattern 55555 4444 333 22 1
🚀 Programming Example

Program to print the given number pattern
55555
4444
333
22
1

👁 24,644 Views
💻 Practical Program
📘 Step Learning
Write a C program to print the given number pattern using loop. How to print the given number pattern using for loop in C programming. Logic to print the given number pattern using loop in C program.

💻 Program Code

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

#include <stdio.h>

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

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

    for(i=N; i>=1; i--)
    {
        for(j=1; j<=i; j++)
        {
            printf("%d", i);
        }

        printf("\n");
    }

    return 0;

}
                        

🖥 Program Output

Enter N: 5
55555
4444
333
22
1
                            

📘 Explanation

Required knowledge

Basic C programming, Loop

Logic to print the given number pattern 1

Before we discuss about logic of printing these patterns. I would recommend you to check out some similar number patterns. As both of the patterns mentioned in this program are just vertically flipped image of

Now, moving on to the logic of first pattern that we need to print. Have a careful eye on to the below pattern

Logic to print the above pattern:

  1. To iterate through rows, initialize an outer loop from N to 1 (where N is the total number of rows). Note that I have initialized the loop from N to 1 not from 1 to N as the pattern is in descending order hence it will help in the inner loop. As both 1 to N or N to 1 will iterate N times.
  2. To print numbers, initialize an inner loop from 1 to current_row_number (note that the current row number will be like n.., 4, 3...1 in decreasing order). Inside this loop print the value of current_row_number.

And you are done, lets implement this now.

📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.