C program to print rectangle pattern of numbers

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

#include <stdio.h>

int main() {
    int rows, cols;

    printf("Enter the number of rows: ");
    scanf("%d", &rows);

    printf("Enter the number of columns: ");
    scanf("%d", &cols);

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

    return 0;

This program will create a rectangular pattern of numbers where each cell contains the product of the row and column numbers.

For example, if you input 3 for the number of rows and 4 for the number of columns, the program will generate the following pattern:

 1  2  3  4
 2  4  6  8
 3  6  9 12 

You can adjust the number of rows and columns by changing the values 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