C program to print square pattern of numbers

 Here's a C program to print a square pattern of numbers:

#include <stdio.h>

int main() {
    int n;

    printf("Enter the size of the square: ");
    scanf("%d", &n);

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            printf("%2d ", i);
        }
        printf("\n");
    }

    return 0;

This program will create a square pattern of numbers where each row contains the same number, and the number increases with each row.

For example, if you input 4 for the size of the square, the program will generate the following pattern:

 1  1  1  1
 2  2  2  2
 3  3  3  3
 4  4  4  4 

You can adjust the size of the square by changing the value you enter when prompted.

Prasun Barua

Prasun Barua is an Engineer (Electrical & Electronic) and Member of the European Energy Centre (EEC). His first published book Green Planet is all about green technologies and science. His other published books are Solar PV System Design and Technology, Electricity from Renewable Energy, Tech Know Solar PV System, C Coding Practice, AI and Robotics Overview, Robotics and Artificial Intelligence, Know How Solar PV System, Know The Product, Solar PV Technology Overview, Home Appliances Overview, Tech Know Solar PV System, C Programming Practice, etc. These books are available at Google Books, Google Play, Amazon and other platforms.

*

Post a Comment (0)
Previous Post Next Post