#include<stdio.h>//header file
#include<conio.h>//header file

void main() //starting of the main() function
{
int a[5][5],b[5][5],c[5][5]; //declaration of the variables
int i,j,k,r1,c1,r2,c2;
clrscr();
printf("program for the multiplication of two matricess");
printf("\n\n\n\t\t------------INPUT-------------");
printf("\n\nenter the rows and columns of first matrix:->");//taking input from the user
scanf("%d %d",&r1,&c1);
printf("\n\nenter the rows and columns of the second matrix:->");
scanf("%d %d",&r2,&c2);
if(c1!=r2)
{
printf("\nthe matrics are not compatible for multiplication");
getch();
exit(0);
}
else
{
printf("\nenter the elements in the first matrix");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf("a[%d][%d]:->",i,j);
scanf("%d",&a[i][j]);
}
}
printf("\nenter the elements in the second matrix");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf("b[%d][%d]:->",i,j);
scanf("%d",&b[i][j]);
}
}
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
c[i][j]=0;
for(k=0;k<c1;k++)
{
c[i][j]+=(a[i][k]*b[k][j]);
}
}
}
printf("\n\n\n\t\t------------OUTPUT------------");
printf("\nthe required matrix after multiplication is=");
printf("\n\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
printf("\tc[%d][%d]:->%d",i,j,c[i][j]);//printing output
}
printf("\n");
}
}
getch();
}