Square Star Pattern

Program to Print Square Star Pattern

PRINTING PATTERN:

****

****

****

****
            

PREREQUISITE:

Basic knowledge of C language and loops.

ALGORITHM:

1. Take number of rows as input from the user (length of the square's side) and store it in a variable ('l').
2. Run a loop 'l' times to iterate through the rows (i=0 to i<l).
3. Run a nested loop inside the previous loop to iterate through the columns (j=0 to j<l).
4. Print ‘*’ inside the nested loop to display stars in all columns of a row.
5. Move to the next line by printing a new line (printf("\n")).

Code in C:

#include <stdio.h>   
int main() {
    int i, j, l;  // Declaring integers i, j for loops and l for number of rows
    printf("Enter the number of rows/columns\n");  // Asking user for input
    scanf("%d", &l);  // Taking input for number of rows
    for (i = 0; i < l; i++) {  // Outer loop for number of rows  
        for (j = 0; j < l; j++) {  // Inner loop for number of columns in each row
            printf("*");  // Printing '*' in each column of a row.
        }
        printf("\n");  // Printing a new line after each row has been printed.
    }
    return 0;
}
            

Output:

Enter the number of rows/columns
4
****
****
****
****