You are on page 1of 2

"/*-------------------------------

mulmatrics.c

Program to perform multiplication of


matrices

Winston D'mello
27-10-2022
-------------------------------*/
#include<stdio.h>
#include<stdlib.h>
//Function Prototypes:
void fnInputMtx(int m, int n, int arr[5][5]);
void fnPrintMtx(int m, int n, int arr[5][5]);
void fnMulMtx(int m, int n,int p, int arr1[5][5],int arr2[5][5],int res[5][5]);

void main()
{
int M,N,O,P;
printf("Enter The Order of the First Matrix(MxN):\n");
scanf("%d%d",&M,&N);
printf("Enter The Order of the Second Matrix(NxP):\n");
scanf("%d%d",&O,&P);

if(N==O){

int X[M][N],Y[O][P],Z[M][P];
printf("Input Matrix A:\n");
fnInputMtx(M, N, X);
printf("Input Matrix B:\n");
fnInputMtx(O, P, Y);
fnMulMtx(M, N, P, X, Y, Z);
printf("Product Of Matrix A and B =\n");
fnPrintMtx(M, N, Z);
}else{
printf("Number of Columns of 1st Matrix and Number of Rows of 2nd
Matrix Does Not Match!!");
printf("\nMultiplication Is Not Possible");
}
}

//functions
//-------------Function to Input Matrix---------------
void fnInputMtx(int m, int n, int arr[5][5])
{
int I,J;
for (I = 1; I <= m; I++)
{
for (J = 1; J <= n; J++) {
scanf("%d", &arr[I][J]);
}
}
}

//-------------Function to Print Matrix---------------


void fnPrintMtx(int m, int n, int arr[5][5])
{
int I,J;
for (I = 1; I <= m; I++)
{
for (J = 1; J <= n; J++) {
printf("%d\t",arr[I][J]);
}
printf("\n");
}
}

//-------------Function to Multiply Matrices---------------


void fnMulMtx(int m, int n,int p, int arr1[5][5],int arr2[5][5],int res[5][5])
{
int I,J,K;
for (I=1;I<=m;I++){
for(J=1;J<=p;J++){
res[I][J] = 0;
for(K=1;K<=n;K++){
res[I][J] += arr1[I][K]*arr2[K][J];
}
}
}
}"

You might also like