#include<conio.h>
#include<stdio.h>
main()
{
int a[5][5],b[5][5],c[5][5],m,n,o,p,i,j,sum,k;
clrscr();
printf("Enter the A Matrix size:\n");
scanf("%d%d",&m,&n);
printf("Enter the A Matrix Elements\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("Enter the B Matrix size:\n");
scanf("%d%d",&o,&p);
printf("Enter the B Matrix Elements\n");
for(i=0;i<o;i++)
for(j=0;j<p;j++)
scanf("%d",&b[i][j]);
if(n!=o)
printf("The 1st Matrix Column are shoul equal to 2nd Matrix Rows");
else
{
for(i=0;i<m;i++)
{
for(j=0;j<p;j++)
{
sum=0;
for(k=0;k<n;k++)
{
sum=sum+a[i][k]*b[k][j];
}
c[i][j]=sum;
}
}
printf("Enter the AxB Matrix Elements\n");
for(i=0;i<o;i++)
{
printf("\n");
for(j=0;j<p;j++)
printf("%d\t",c[i][j]);
}
}
getch();
}
Out Put:
#include<stdio.h>
main()
{
int a[5][5],b[5][5],c[5][5],m,n,o,p,i,j,sum,k;
clrscr();
printf("Enter the A Matrix size:\n");
scanf("%d%d",&m,&n);
printf("Enter the A Matrix Elements\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("Enter the B Matrix size:\n");
scanf("%d%d",&o,&p);
printf("Enter the B Matrix Elements\n");
for(i=0;i<o;i++)
for(j=0;j<p;j++)
scanf("%d",&b[i][j]);
if(n!=o)
printf("The 1st Matrix Column are shoul equal to 2nd Matrix Rows");
else
{
for(i=0;i<m;i++)
{
for(j=0;j<p;j++)
{
sum=0;
for(k=0;k<n;k++)
{
sum=sum+a[i][k]*b[k][j];
}
c[i][j]=sum;
}
}
printf("Enter the AxB Matrix Elements\n");
for(i=0;i<o;i++)
{
printf("\n");
for(j=0;j<p;j++)
printf("%d\t",c[i][j]);
}
}
getch();
}
Out Put: