# Multiply Two Matrices C Program

## C Program To Multiply Two Matrices (3 Dimensional)

Learn How To Multiply Two Matrices in C Programming Language. It is important that we should know about **How A For Loop Works **before getting further with the C Program Code. This C Program Multiplies Two 3-Dimensional Matrix (Array of Integers) using For Loop.

**Note:** This Matrix Multiplication C Program is developed in Linux Ubuntu Operating System and compiled with GCC Compiler.

**Also Read: C Program To Calculate Sum of Elements of a 3-Dimensional Matrix**

#### C Program To Multiply Two Matrices

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #include<stdio.h> int main() { int arr1[3][3], arr2[3][3], arr3[3][3]; int i, j, k, sum = 0; printf("Enter First 3*3 Matrix Elements:\n"); for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { scanf("%d", &arr1[i][j]); } } printf("\nEnter Second 3*3 Matrix Elements:\n"); for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { scanf("%d", &arr2[i][j]); } } printf("\nMultiplication of Matrices:\n"); for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { for(k = 0; k < 3; k++) { sum = sum + arr1[i][k]*arr2[k][j]; } arr3[i][j] = sum; sum = 0; } } printf("\nThird Matrix Elements:\n"); for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { printf("%d\t", arr3[i][j]); } printf("\n"); } printf("\n"); return 0; } |

**Also Read: C Program To Find Major and Minor Diagonals of a Matrix**

#### Output

If you have any Compilation Error or Doubts in this C Program for Multiplication of Two Matrices, let us know about it in the comment section below.

Simple and Self-Explanatory program. Thanks.

Yes. We focus on keeping the program structure simple enough for the users to understand it effeftively.