luc067.c ​
Metadata ​
- Author — Amit Dutta
- Last updated — 08 Feb 2026
- License — MIT License (See the LICENSE file for details)
Problem Statement ​
Problem Statement
Write a program to multiply any two 3 x 3 matrices.
Source Code ​
Printing the code
To print this file, open it on GitHub and click Raw before printing, or use the Download Raw button above and print directly from that page.
c
#include <stdio.h>
#include <stdlib.h>
int main()
{
int mat1[3][3], mat2[3][3], res[3][3];
int i, j, k;
printf("Enter elements of first 3x3 matrix:\n");
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
scanf("%d", &mat1[i][j]);
printf("Enter elements of second 3x3 matrix:\n");
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
scanf("%d", &mat2[i][j]);
// Initialize result matrix to 0
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
res[i][j] = 0;
// Multiplication Logic
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
for (k = 0; k < 3; k++)
{
res[i][j] += mat1[i][k] * mat2[k][j];
}
}
}
printf("\nResult of Multiplication:\n");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
printf("%4d ", res[i][j]);
}
printf("\n");
}
return 0;
}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
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