fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int a[100][100],b[100][100];
  5. long c[100][100];
  6.  
  7. int main() {
  8. int ar,ac,br,bc;
  9. while(cin>>ar>>ac>>br>>bc){
  10. if(ac!=br){
  11. cout<<"Error\n";continue;
  12. }for(int i=0;i<ar;i++)for(int j=0;j<ac;j++)cin>>a[i][j];
  13. for(int i=0;i<br;i++)for(int j=0;j<bc;j++)cin>>b[i][j];
  14. //for(int i=0;i<ar;i++){for(int j=0;j<ac;j++)cout<<a[i][j]<<" ";cout<<"\n";}
  15. //for(int i=0;i<br;i++){for(int j=0;j<bc;j++)cout<<b[i][j]<<" ";cout<<"\n";}
  16. for(int i=0;i<ar;i++)for(int j=0;j<bc;j++){
  17. c[i][j]=0;
  18. for(int k=0;k<ac;k++){
  19. c[i][j]+=(long)a[i][k]*b[k][j];
  20. }
  21. }for(int i=0;i<ar;i++){for(int j=0;j<bc;j++) cout<<c[i][j]<<" "; cout<<"\n";}
  22. }
  23. }
Success #stdin #stdout 0.01s 5312KB
stdin
3 2 2 3
1 2
3 4
5 6
1 2 3
4 5 6
1 2 3 4
stdout
9 12 15 
19 26 33 
29 40 51 
Error