fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main(void)
  6. {
  7. int n, m, k;
  8. int a[101][101], b[101][101], r[101][101] = { 0, };
  9.  
  10. //행렬 a입력
  11. cin >> n >> m;
  12. for (int i = 0; i < n; i++)
  13. for (int j = 0; j < m; j++)
  14. cin >> a[i][j];
  15.  
  16. //행렬 b입력
  17. cin >> m >> k;
  18. for (int i = 0; i < m; i++)
  19. for (int j = 0; j < k; j++)
  20. cin >> b[i][j];
  21.  
  22. //행렬의 곱 실행
  23. for (int i = 0; i < n; i++)
  24. for (int j = 0; j < k; j++)
  25. for (int u = 0; u < m; u++)
  26. r[i][j] += a[i][u] * b[u][j];
  27.  
  28. //출력
  29. for (int i = 0; i < n; i++)
  30. {
  31. for (int j = 0; j < k; j++)
  32. cout << r[i][j] << " ";
  33. cout << endl;
  34. }
  35. }
  36.  
Success #stdin #stdout 0s 5600KB
stdin
3 2
1 2
3 4
5 6
2 3
-1 -2 0
0 0 3
stdout
-1 -2 6 
-3 -6 12 
-5 -10 18