-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.c
More file actions
50 lines (41 loc) · 931 Bytes
/
Copy pathsample.c
File metadata and controls
50 lines (41 loc) · 931 Bytes
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
48
49
50
#include <stdio.h>
#include <stdlib.h>
#define N 4
void matrixMultiply(int A[N][N], int B[N][N], int C[N][N]) {
int i, j, k;
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
C[i][j] = 0;
for (k = 0; k < N; k++) {
C[i][j] += A[i][k] * B[k][j];
}
}
}
}
void printMatrix(int matrix[N][N]) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
printf("%d ", matrix[i][j]);
}
printf("\n");
}
}
int main() {
int A[N][N] = {
{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12},
{13, 14, 15, 16}
};
int B[N][N] = {
{17, 18, 19, 20},
{21, 22, 23, 24},
{25, 26, 27, 28},
{29, 30, 31, 32}
};
int C[N][N]; // Result matrix
matrixMultiply(A, B, C);
printf("Resultant matrix:\n");
printMatrix(C);
return 0;
}