-
Notifications
You must be signed in to change notification settings - Fork 9
/
news0.cpp
57 lines (40 loc) · 876 Bytes
/
news0.cpp
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
52
53
54
55
56
#include <stdio.h>
#include <stdlib.h>
#define R1 2
#define C1 2
#define R2 2
#define C2 2
void mulMat(int mat1[][C1], int mat2[][C2])
{
int rslt[R1][C2];
printf("Multiplication of given two matrices is:\n");
for (int i = 0; i < R1; i++) {
for (int j = 0; j < C2; j++) {
rslt[i][j] = 0;
for (int k = 0; k < R2; k++) {
rslt[i][j] += mat1[i][k] * mat2[k][j];
}
printf("%d\t", rslt[i][j]);
}
printf("\n");
}
}
int main()
{
int mat1[R1][C1] = { { 1, 1 },
{ 2, 2 } };
int mat2[R2][C2] = { { 1, 1 },
{ 2, 2 } };
if (C1 != R2) {
printf("The number of columns in Matrix-1 must be "
"equal to the number of rows in "
"Matrix-2\n");
printf("Please update MACROs value according to "
"your array dimension in "
"#define section\n");
exit(EXIT_FAILURE);
}
// Function call
mulMat(mat1, mat2);
return 0;
}