-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiplication of matrix.C
More file actions
51 lines (39 loc) · 1.22 KB
/
Multiplication of matrix.C
File metadata and controls
51 lines (39 loc) · 1.22 KB
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
51
#include <stdio.h>
int main() {
int r1, c1, r2, c2;
printf("Enter rows and columns of Matrix 1: ");
scanf("%d %d", &r1, &c1);
printf("Enter rows and columns of Matrix 2: ");
scanf("%d %d", &r2, &c2);
if (c1 != r2) {
printf("Matrix multiplication not possible!\n");
return 0;
}
int A[r1][c1], B[r2][c2], result[r1][c2];
printf("Enter elements of Matrix 1:\n");
for (int i = 0; i < r1; i++)
for (int j = 0; j < c1; j++)
scanf("%d", &A[i][j]);
printf("Enter elements of Matrix 2:\n");
for (int i = 0; i < r2; i++)
for (int j = 0; j < c2; j++)
scanf("%d", &B[i][j]);
for (int i = 0; i < r1; i++)
for (int j = 0; j < c2; j++)
result[i][j] = 0;
for (int i = 0; i < r1; i++) {
for (int j = 0; j < c2; j++) {
for (int k = 0; k < c1; k++) {
result[i][j] += A[i][k] * B[k][j];
}
}
}
printf("Result of Matrix Multiplication:\n");
for (int i = 0; i < r1; i++) {
for (int j = 0; j < c2; j++) {
printf("%d ", result[i][j]);
}
printf("\n");
}
return 0;
}