fork download
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. using std::cin;
  5. using std::cout;
  6. using std::endl;
  7.  
  8. int main()
  9. {
  10. cout << "n, m:" << endl;
  11. int i, j, n, m;
  12. cin >> n >> m;
  13. int** a = new int*[n];
  14. cout << "Matrix A:" << endl;
  15. for (i = 0; i < n; i++) {
  16. a[i] = new int[m];
  17. for (j = 0; j < m; j++)
  18. cin >> a[i][j];
  19. }
  20. int** b = new int*[n];
  21. cout << "Matrix B:" << endl;
  22. for (i = 0; i < n; i++) {
  23. b[i] = new int[m];
  24. for (j = 0; j < m; j++)
  25. cin >> b[i][j];
  26. }
  27. for (i = 0; i < n; i++) {
  28. for (j = 0; j < m; j++)
  29. a[i][j] += b[i][j];
  30. delete[ ] b[i];
  31. }
  32. delete[ ] b;
  33. for (i = 0; i < n; i++)
  34. {
  35. for (j = 0; j < m; j++)
  36. cout << a[i][j] << ' ';
  37. cout << endl;
  38. delete[ ] a[i];
  39. }
  40. delete[ ] a;
  41. system("pause");
  42. }
  43.  
Success #stdin #stdout #stderr 0s 3476KB
stdin
4 5
17 1 10 14 4
4 7 7 11 2
17 17 11 7 20
9 8 7 2 2

8 18 10 3 2
18 6 16 11 16
12 16 15 14 15
12 9 6 2 2
stdout
n, m:
Matrix A:
Matrix B:
25 19 20 17 6 
22 13 23 22 18 
29 33 26 21 35 
21 17 13 4 4 
stderr
sh: pause: not found