# C program for matrix multiplication

A matrix is a multi-dimensional array of elements. This C program multiplies the two matrices together using the concept of matrix multiplication.

#include<stdio.h>
int main(){
int m,n,a[100][100],i,j,b[100][100],multiply[100][100],p,q,sum=0,k;
printf("enter number of rows of first matrix ");
scanf("%d",&m);
printf("enter number of colomns of first matrix");
scanf("%d",&n);
for(i=0;i<m;i++)
for(j=0;j<n;j++){
printf("Enter Element at %d%d position of first matrix",i+1,j+1);
scanf("%d",&a[i][j]);

}
printf("\n \n");

printf("enter number of rows of second matrix ");
scanf("%d",&p);
printf("enter number of colomns of second matrix");
scanf("%d",&q);
for(i=0;i<p;i++)
for(j=0;j<q;j++){
printf("Enter Element at %d%d position of second matrix",i+1,j+1);
scanf("%d",&b[i][j]);

}

printf("\n \n");
if(n!=p){
printf("matrices can't be multiplied!!");
exit(1);
}

for(i=0;i<m;i++){
for(j=0;j<q;j++){
for(k=0;k<n;k++){
sum+=a[i][k]*b[k][j];

}
multiply[i][j]=sum;
sum=0;
}
}
printf("\n multiplied matrix \n");

for(i=0;i<m;i++){
for(j=0;j<q;j++){
printf(" %d ",multiply[i][j]);
}
printf("\n");
}

return 0;
}

Output