# C Program to find sum of two numbers

#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],b[3][3],c[3][3],i,j,l,m1,n1,m2,n2,s=0;
clrscr();
printf("\nEnter number of rows and columns of first matrix:");
scanf("%d%d",&m1,&n1);
printf("\nEnter elements in first matrix:");
for(i=0;i {
for(j=0;j {
printf("\na[%d][%d]=",i,j);
scanf("%d",&a[i][j]);
}
}
printf("\nEnter number of rows and columns of second matrix:");
scanf("%d%d",&m2,&n2);
printf("\nEnter elements in second matrix:");
for(i=0;i {
for(j=0;j {
printf("\nb[%d][%d]=",i,j);
scanf("%d",&b[i][j]);
}
}
if(n1!=m2)
{
printf("\nMultiplication is not possible");
}
else
{
for(i=0;i {
for(j=0;j {
for(l=0;l {
s=s+a[i][l]*b[l][j];
}
c[i][j]=s;
s=0;
}
}
printf("\nMultiplication of two matrices is:");
for(i=0;i {
for(j=0;j {
printf("\nc[%d][%d]=%d",i,j,c[i][j]);
}
printf("\n");
}
}
getch();
}

## Explanation:

The above program will multiply two matrices. We can understand this process by following example:

s=0
m1=1, n1=2
a[0][0]=2,a[0][1]=4
m2=2,n2=2
b[0][0]=2,b[0][1]=2,b[1][0]=2,b[1][1]=2
n1!=m2,False
i=0
i iteration 1: (Outer loop)
j=0
j iteration 1: (Middle loop)
l=0
l iteration 1: (Inner loop)
s=s+a[i][l]*b[l][j];
so s=0+a[0][0]*b[0][0]=4
Increment l by 1 so l=1
l Iteration 2: (Inner loop)
s=4+a[0][1]*b[1][0]=4+8=12
Increment l by 1 so 1=2
l Now c[i][j]=s
c[0][0]=12
s=0
increment j by 1 so j=1
j iteration 2: (Middle loop)
l iteration1;(inner loop)
s=s+a[i][l]*b[l][j];
s=0+a[0][0]*b[0][1]=4
Increment l by 1 so l=1
l iteration2: (inner loop)
s=4+a[0][1]*b[1][1]=12
Increment l by l so l=2
l c[0][1]=12
s=0
Increment j by 1 now j=2
j Increment I by 1 now i=1
i
So we get the following output after the multiplication of given matrices: