# Write a C program to multiply 2 matrices

Write a program to multiply 2 matrices

void main()
{
int m1[10][10],m2[10][10],rm[10][10]; /matrix declared/
int count3,count1,count2,r1,r2,c1,c2;

``````printf("Enter the order of first matrix: ");
scanf("%d%d",&amp;r1,&amp;c1); /*values entered*/

printf("Enter the order of second matrix: ");
scanf("%d%d",&amp;r2,&amp;c2);

if(c1==r2) /*Control statement*/
{
printf("Enter the element of first matrix:");
for(count1=0;count1 {
for(count2=0;count2 {
scanf("%d",&amp;m1[count1][count2]);
}
}

printf("Enter the element of second matrix:");
for(count1=0;count1{
for(count2=0;count2 {
scanf("%d",&amp;m2[count1][count2]);
}
}

printf("
``````

The element of matrix m1 :"); /entering elements/
for(count1=0;count1{
printf("
“);
for(count2=0;count2 {
printf(”%d",m1[count1][count2]);
printf(" ");
}
}

``````printf("
``````

The element of matrix m2 :");
for(count1=0;count1{
printf("
“);
for(count2=0;count2 {
printf(”%d",m2[count1][count2]);
printf(" ");
}
}

``````for(count1=0;count1{
for(count2=0;count2 {
rm[count1][count2]=0;
for(count3=0;count3 {
rm[count1][count2] =rm[count1][count2]
+m1[count1][count3]*m2[count3][count2];
}
}
}

printf("
``````

The element of resultant matrix:"); /resultant matrix/
for(count1=0;count1{
printf("
“);
for(count2=0;count2 {
printf(“4%d”,rm[count1][count2]);
printf(” “);
}
}
else
printf(”
Multiplication of the matrix is not possible.");
}