Home C Programming Language / Programs / Program to print the given pattern 11111 22222 33333 44444 55555
🚀 Programming Example

Program to print the given pattern
11111
22222
33333
44444
55555

👁 26,175 Views
💻 Practical Program
📘 Step Learning
Write a C program to print the given number pattern using for 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 rows, cols, i, j;

    /* Input rows and columns from user */
    printf("Enter number of rows: ");
    scanf("%d", &rows);
    printf("Enter number of columns: ");
    scanf("%d", &cols);

    for(i=1; i<=rows; i++)
    {
        for(j=1; j<=cols; j++)
        {
            // Print the current row number
            printf("%d", i);
        }

        printf("\n");
    }

    return 0;
}
                        

🖥 Program Output

Enter number of rows: 5
Enter number of columns: 5
11111
22222
33333
44444
55555
                            

📘 Explanation

Required knowledge

Basic C programming, Loop

Logic to print the given pattern

Below is the step by step descriptive logic to print the given number pattern.

  1. Input number of rows and columns to print from user. Store it in some variable say rows and cols.
  2. To iterate through rows run an outer loop from 1 to rows. The loop structure should look like for(i=1; i<=rows; i++).
  3. To iterate through columns run an inner loop from 1 to cols. The loop structure should look like for(j=1; j<=cols; j++).
  4. Now, for each row the current row number is printed. Hence, print the value of i to print current row number.
  5. Finally move to next line after printing all columns of a row.
📚 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.