Home C Programming Language / Programs / C program to print square or rectangle star pattern ******************** ******************** ******************** ******************** ********************
🚀 Programming Example

C program to print square or rectangle star pattern
********************
********************
********************
********************
********************

👁 3,334 Views
💻 Practical Program
📘 Step Learning
Write a C program to print square star(*) pattern series of N rows. C program to print rectangle star(*) pattern in C of N rows and M columns. Logic to print square or rectangle star pattern of N rows in C programming.

💻 Program Code

/**
 * C program to print rectangle star pattern
 */

#include <stdio.h>

int main()
{
    int i, j, rows, columns;

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

    /* Iterate through each row */
    for(i=1; i<=rows; i++)
    {
        /* Iterate through each column */
        for(j=1; j<=columns; j++)
        {
            /* For each column print star */
            printf("*");
        }
        
        /* Move to the next line/row */
        printf("\n");
    }

    return 0;
}
                        

🖥 Program Output

Enter number of rows: 5
Enter number of columns: 10
**********
**********
**********
**********
**********
                            

📘 Explanation

Step by step descriptive logic to print rectangle star pattern.

  1. Input number of rows and columns from user. Store it in a variable say?rows?and?columns.
  2. To iterate through rows, run an outer loop from 1 to?rows. Define a loop with structure?for(i=1; i<=rows; i++).
  3. To iterate through columns, run an inner loop from 1 to?columns. Define a loop with structure?for(j=1; j<=columns; j++).
  4. Inside inner loop print star?*.
  5. After printing all columns of a row. Move to next line i.e. print a new line.
📚 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.