Basic Square 1 Pattern

Program to Print Basic Square 1 Pattern

PRINTING PATTERN:

1111
1111
1111
1111
            

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 ('n' for rows and 'm' for columns).
2. Run a loop 'n' times to iterate through the rows.
3. For each row, run another loop 'm' times to print '1'.
4. Move to the next line after each row has been printed.

Code in C:

#include <stdio.h>

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

    // Loop to print the square pattern
    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            printf("1");  // Printing '1'
        }
        printf("\n");  // New line after each row
    }

    return 0;
}
            

Output:

Enter the number of rows and columns for the square pattern:
4 4
1111
1111
1111
1111