MATRIX MULTIPLICATION
#include <stdio.h>
#include<conio.h>
void multiplyMatrices(int firstMatrix[10][10],int secondMatrix[10][10],int result[10][10],int
row1, int col1,int row2,int col2) {
int i,j,k;
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] += firstMatrix[i][k] * secondMatrix[k][j];
}
}
}
}
void displayMatrix(int matrix[][10], int row, int col) { int i,j;
for (i = 0; i < row; i++) {
for (j = 0; j < col; j++) {
printf("%d\t", matrix[i][j]);
}
printf("\n");
}
}
int main() { int i,j;
int row1, col1, row2, col2;
int firstMatrix[10][10], secondMatrix[10][10], result[10][10];
printf("Enter rows and columns for first matrix: ");
scanf("%d %d", &row1, &col1);
printf("Enter rows and columns for second matrix: ");
scanf("%d %d", &row2, &col2);
if (col1 != row2) {
printf("Error! Column of first matrix must be equal to row of second matrix.\n");
return 1;
}
printf("Enter elements of first matrix:\n");
for (i = 0; i < row1; i++)
for (j = 0; j < col1; j++)
scanf("%d", &firstMatrix[i][j]);
printf("Enter elements of second matrix:\n");
for (i = 0; i < row2; i++)
for (j = 0; j < col2; j++)
scanf("%d", &secondMatrix[i][j]);
multiplyMatrices(firstMatrix, secondMatrix, result, row1, col1, row2, col2);
printf("Resultant Matrix:\n");
displayMatrix(result, row1, col2);
getch();
return 0;
}