Posted in: C Language

C Program to Multiply two Matrix

For writing this program you need to have knowledge of the following concepts and have a good practice :

  1. Array
  2. For loop
  3. Matrix [Mathematics]

Program:

#include<stdio.h>    
 
int main()
{  
int mat1[3][3],mat2[3][3],pd[3][3],i,j,k;    
printf("Enter the elements of first matrix : \n");    
for(i=0;i<3;i++)    
{    
for(j=0;j<3;j++)    
{    
scanf("%d",&mat1[i][j]);    
}    
}    
printf("Enter the elements or second matrix : \n");    
for(i=0;i<3;i++)    
{    
for(j=0;j<3;j++)    
{    
scanf("%d",&mat2[i][j]);    
}    
}    
   
printf("Multiplication of Matrix : \n");    
for(i=0;i<3;i++)    
{    
for(j=0;j<3;j++)    
{    
pd[i][j]=0;    
for(k=0;k<3;k++)    
{    
pd[i][j]+=mat1[i][k]*mat2[k][j];    
}    
}    
}      
for(i=0;i<3;i++)    
{    
for(j=0;j<3;j++)    
{    
printf("%d\t",pd[i][j]);    
}    
printf("\n");    
}    
return 0;  
}

Output

Download