-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.cpp
More file actions
54 lines (54 loc) · 977 Bytes
/
basic.cpp
File metadata and controls
54 lines (54 loc) · 977 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
51
52
53
54
#include <iostream>
using namespace std;
int main()
{
int n, m, p, q;
cin >> n >> m >> p >> q;
if (m != p)
{
cout << "matrix multiplication not possible";
exit(0);
}
int k = n;
int l = q;
int A[n][m];
int B[p][q];
int C[k][l];
for (auto &i : A)
{
for (auto &j : i)
{
cin >> j;
}
}
for (auto &i : B)
{
for (auto &j : i)
{
cin >> j;
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
for (int k = 0; k < p; k++)
{
for (int l = 0; l < q; l++)
{
C[k][l] += A[i][j] * B[p][q];
}
}
}
}
cout << "resultant matrix is :" << endl;
for (auto &i : C)
{
for (auto &j : i)
{
cout << j << " ";
}
cout << endl;
}
return 0;
}