Home C Programming Language / Programs / Program to print the given number pattern 11111 2222 333 44 5
🚀 Programming Example

Program to print the given number pattern
11111
2222
333
44
5

👁 6,546 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=1; i<=N; i++)
    {
        // Logic to print numbers
        for(j=i; j<=N; j++)
        {
            printf("%d", i);
        }

        printf("\n");
    }

    return 0;
}
                        

🖥 Program Output

Enter N: 5
11111
2222
333
44
5
                            

📘 Explanation

Required knowledge

Basic C Programming, Loop

Logic to print the given number pattern

To get the logic of above pattern just have a close eye on the pattern. Lets suppose that the rows starts from 1 to N (where N is the total rows to be printed). Then total columns per row is N - current_row_number + 1 i.e. first row contains 5 - 1 + 1 = 5 columns and so on. And for each column the current row number gets printed. Hence, the step by step descriptive logic to print the given logic is:

  1. To iterate through rows, start an outer loop from 1 to N.
  2. To print the numbers, start an inner loop from current row number to N. Inside this loop print the value of current row number.

And you are done, lets now write down its code.

📚 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.