Product of two matrices

PRODUCT OF TWO MATRICES :

#include< stdio.h >
main()
{
int a[5][5],b[5][5],c[5][5],i,j,l,r1,c1,r2,c2;

printf("\nEnter the order for first matrix ");
scanf("%d%d",&r1,&c1)
r2=c1;
printf("\nEnter the number of columns for second  matrix ");
scanf("%d",&c2);

printf("\nEnter the elements for first matrix \n");
for( i=0; i < r1; i++ )

{
  for( j=0; j < c1 ; j++ )

    {
         scanf("%d",&a[i][j]);
    }
}

printf("\nEnter the elements for second matrix \n");

for( i=0; i < r2; i++ )
{
  for( j=0; j < c2 ; j++ )

    {         
           scanf("%d",&b[i][j]);
    }
}

for( i=0; i < r1; i++ )
{
  for( j=0; j < c2 ; j++ )

    {
         c[i][j]=0;
  for( l=0; l < c1 ; l++)  

   {  
       c[i][j]=c[i][j] + a[i][l] * b[l][j];
     }
   }
}

printf("\nElements of array are \n");

for( i=0; i < r1; i++ )
{
  for( j=0; j < c2 ; j++ )

    {       
              printf("%3d",c[i][j]);
     }
   printf("\n");
}
}

Comments