-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix_Multiplication.cpp
More file actions
51 lines (50 loc) · 971 Bytes
/
Matrix_Multiplication.cpp
File metadata and controls
51 lines (50 loc) · 971 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
#include <iostream>
using namespace std;
int main()
{
int n1, n2, n3;
cin >> n1 >> n2 >> n3;
int a[n1][n2], b[n2][n3];
for (int i = 0; i < n1; i++)
{
for (int j = 0; j < n2; j++)
{
cin >> a[i][j];
}
}
for (int i = 0; i < n2; i++)
{
for (int j = 0; j < n3; j++)
{
cin >> b[i][j];
}
}
int ans[n1][n3];
for (int i = 0; i < n1; i++)
{
for (int j = 0; j < n3; j++)
{
ans[i][j] = 0;
}
}
for (int i = 0; i < n1; i++)
{
for (int j = 0; j < n3; j++)
{
for (int k = 0; k < n2; k++)
{
ans[i][j] += a[i][k] * b[k][j];
}
}
}
cout << "Answer : " << endl;
for (int i = 0; i < n1; i++)
{
for (int j = 0; j < n3; j++)
{
cout << ans[i][j] << " ";
}
cout << endl;
}
return 0;
}