fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, m;
  6. cin >> n >> m;
  7. int matrix1[n][m];
  8. int matrix2[n][m];
  9. int matrix_sum[n][m] = {0};
  10. for(int i = 0; i < n; i++){
  11. for(int j = 0; j < m; j++){
  12. cin >> matrix1[i][j];
  13. }
  14. }
  15. for(int i = 0; i < n; i++){
  16. for(int j = 0; j < m; j++){
  17. cin >> matrix2[i][j];
  18. }
  19. }
  20. for(int i = 0; i < n; i++){
  21. for(int j = 0; j < m; j++){
  22. matrix_sum[i][j] = matrix1[i][j] + matrix2[i][j];
  23. cout << matrix_sum[i][j] << " ";
  24. }
  25. cout << endl;
  26. }
  27. return 0;
  28. }
Success #stdin #stdout 0s 4508KB
stdin
3 4
3 4 5 6
1 2 3 4
7 6 5 4

0 0 -3 -2
-1 3 4 5
5 6 1 2
stdout
3 4 2 4 
0 5 7 9 
12 12 6 6