-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrixMultiplaction.cpp
More file actions
47 lines (40 loc) · 976 Bytes
/
matrixMultiplaction.cpp
File metadata and controls
47 lines (40 loc) · 976 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
#include<bits/stdc++.h>
using namespace std;
int main(){
int m,n;cin>>m>>n;
int matrix1[m][n];
for(int i = 0; i < m; i ++){
for(int j = 0; j < n; j++){
cin>>matrix1[i][j];
}
}
int nr, q;cin>>nr>>q;
int matrix2[nr][q];
for(int i = 0; i < nr; i++){
for(int j = 0; j < q; j++){
cin>>matrix2[i][j];
}
}
if(n != nr){
cout<<-1;
}else{
int multi[m][q] = {0 , 0};
int ans;
for(int i = 0; i < m; i++){
for(int j = 0; j < q; j++){
ans = 0;
for(int k = 0; k < n; k++){
ans += matrix1[i][k] * matrix2[k][j];
}
multi[i][j] = ans;
}
}
cout<<m<< ' '<<q<<endl;
for(int i = 0; i < m; i++){
for(int j = 0; j < q; j++){
cout<<multi[i][j]<<' ';
}
cout<<endl;
}
}
}