Write a c program to calculate Multiplication of two matrix of order m*n

#include<stdio.h>
#include<stdlib.h>
int main()
{
//declaration of 2 matrix a and b
       //r=rows , c=columns
int a[10][10],b[10][10],mul[10][10],r,c,i,j,k;

   //accept rows and columns
printf("\nEnter the number of rows: ");
scanf("%d",&r);
printf("\nEnter the number of columns: ");
scanf("%d",&c);

   //accept 1st matrix
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
      printf("\nEnter %d element: ",i+1);
scanf("%d",&a[i][j]);
}
}

   //accept 2nd matrix
printf("\nEnter the elements of second matrix \n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
      printf("\nEnter %d element: ",i+1);
scanf("%d",&b[i][j]);
}
}

   //multiplication of 2 matrix
printf("\nMultiplication of the matrix:\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
mul[i][j]=0;
for(k=0;k<c;k++)
{
mul[i][j]+=a[i][k]*b[k][j];
}
}
}

//for printing multiplication matrix
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d\t",mul[i][j]);
}
printf("\n");
}
return 0;
}

0 Comments