fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N=101;
  5. long a[N][N],b[N][N],c[N][N];
  6.  
  7. int main(){
  8. int r1, r2, c1, c2;
  9. while(cin>>r1>>c1>>r2>>c2){
  10. if(c1!=r2){
  11. cout<<"Error\n";
  12. continue;
  13. }
  14. for(int i=0; i<r1; i++)
  15. for(int j=0; j<c2; j++)
  16. c[i][j]=0;
  17.  
  18. for(int i=0; i<r1; i++)
  19. for(int j=0; j<c1; j++)
  20. cin>>a[i][j];
  21.  
  22. for(int i=0; i<r2; i++)
  23. for(int j=0; j<c2; j++)
  24. cin>>b[i][j];
  25.  
  26. for(int i=0; i<r1; i++){
  27. for(int j=0; j<c2; j++){
  28. for(int k=0; k<c1; k++)
  29. c[i][j]+=a[i][k]*b[k][j];
  30. }
  31. }
  32.  
  33. for(int i=0; i<r1; i++){
  34. for(int j=0; j<c2; j++)
  35. cout<<c[i][j]<<' ';
  36. cout<<'\n';
  37. }
  38. }
  39. }
Success #stdin #stdout 0.01s 5280KB
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