-
Notifications
You must be signed in to change notification settings - Fork 0
/
Strassen.c
48 lines (40 loc) · 1.17 KB
/
Strassen.c
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
#include <stdio.h>
void printMatrix(int matrix[3][3]) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
printf("%d ", matrix[i][j]);
}
printf("\n");
}
}
void multiplyMatrices(int A[3][3], int B[3][3], int result[3][3]) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
result[i][j] = 0;
for (int k = 0; k < 3; k++) {
result[i][j] += A[i][k] * B[k][j];
}
}
}
}
int main() {
int A[3][3], B[3][3], C[3][3];
printf("Enter elements for the first 3x3 matrix:\n");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
printf("Enter element A[%d][%d]: ", i, j);
scanf("%d", &A[i][j]);
}
}
printf("\nEnter elements for the second 3x3 matrix:\n");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
printf("Enter element B[%d][%d]: ", i, j);
scanf("%d", &B[i][j]);
}
}
multiplyMatrices(A, B, C);
printf("\nResultant Matrix C (A * B):\n");
printMatrix(C);
return 0;
}