# C Program to Multiply Two Matrices

## Multiply Two Matrices in C

To multiply two matrices in C programming, first ask to the user to enter the two matrix, then start multiplying the two matrices and store the multiplication result inside any variable say sum and finally store the value of sum in the third matrix say mat3[ ][ ]

## C Programming Code to Multiply Two Matrices

Following C program ask to the user to enter the two 3*3 matrix elements, to multiply them to form a new matrix which is the result of the multiplication of the two entered 3*3 matrices, then display the result on the screen:

```/* C Program - Multiply Two Matrices */

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int mat1[3][3], mat2[3][3], mat3[3][3], sum=0, i, j, k;
printf("Enter first matrix element (3*3) : ");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
scanf("%d",&mat1[i][j]);
}
}
printf("Enter second matrix element (3*3) : ");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
scanf("%d",&mat2[i][j]);
}
}
printf("Multiplying two matrices...\n");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
sum=0;
for(k=0; k<3; k++)
{
sum = sum + mat1[i][k] * mat2[k][j];
}
mat3[i][j] = sum;
}
}
printf("\nMultiplication of two Matrices : \n");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
printf("%d  ", mat3[i][j]);
}
printf("\n");
}
getch();
}```

When the above c program is compile and executed, it will produce the following result:

### Same Program in Other Programming Language

You may also like same program in other programming languages:

Tools
Calculator