#include <stdio.h>

int main() {
    int row1, col1, row2, col2, i, j, k;

    printf("Enter dimensions of the first matrix (rows columns): ");
    scanf("%d %d", &row1, &col1);

    printf("Enter dimensions of the second matrix (rows columns): ");
    scanf("%d %d", &row2, &col2);

    if (col1 != row2) {
        printf("Error: Matrices cannot be multiplied. Column of the first matrix must be equal to the row of the second matrix.\n");
        return 1;
    }

    int mat1[row1][col1];
    printf("Enter elements of the first matrix:\n");
    for (i = 0; i < row1; ++i) {
        for (j = 0; j < col1; ++j) {
            scanf("%d", &mat1[i][j]);
        }
    }

    int mat2[row2][col2];
    printf("Enter elements of the second matrix:\n");
    for (i = 0; i < row2; ++i) {
        for (j = 0; j < col2; ++j) {
            scanf("%d", &mat2[i][j]);
        }
    }

    int result[row1][col2];
    for (i = 0; i < row1; ++i) {
        for (j = 0; j < col2; ++j) {
            result[i][j] = 0;
            for (k = 0; k < col1; ++k) {
                result[i][j] += mat1[i][k] * mat2[k][j];
            }
        }
    }

    printf("Resultant Matrix (Multiplication):\n");
    for (i = 0; i < row1; ++i) {
        for (j = 0; j < col2; ++j) {
            printf("%d ", result[i][j]);
        }
        printf("\n");
    }

    return 0;
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: