Rectangle Star Pattern

Program to Print Rectangle Star Pattern

PRINTING PATTERN:

******
******
******
******
            

PREREQUISITE:

Basic knowledge of C language and loops.

ALGORITHM:

1. Take the number of rows and columns as input from the user and store them in variables ('rows' and 'cols').
2. Run a loop 'rows' times to iterate through the rows (i=0 to i<rows).
3. Inside the outer loop, run another loop 'cols' times to iterate through the columns (j=0 to j<cols).
4. Print '*' for each column in the current row.
5. Move to the next line after each row has been printed.

Code in C:

#include <stdio.h>

int main() {
    int rows, cols, i, j;  // Declaring integers for rows, columns, and loop counters
    printf("Enter the number of rows for the rectangle:\n");
    scanf("%d", &rows);  // Taking input for number of rows
    printf("Enter the number of columns for the rectangle:\n");
    scanf("%d", &cols);  // Taking input for number of columns

    for (i = 0; i < rows; i++) {
        for (j = 0; j < cols; j++) {
            printf("*");  // Printing '*' for each column in the current row
        }
        printf("\n");  // New line after each row
    }

    return 0;
}
            

Output:

Enter the number of rows for the rectangle:
4
Enter the number of columns for the rectangle:
6
******
******
******
******