fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_SIZE = 10;
  5.  
  6. void newMatrix(int n, int mt[][MAX_SIZE + 1], int mt2[][MAX_SIZE +1]) {
  7. int newMt[MAX_SIZE + 1][MAX_SIZE + 1];
  8. for (int i = 1; i <= n; ++i) {
  9. for (int j = 1; j <= n; ++j) {
  10. newMt[i][j] = mt[i][j] + mt2[i][j];
  11. cout << newMt[i][j] << " ";
  12. }
  13. cout << "\n";
  14. }
  15.  
  16. }
  17.  
  18. int main() {
  19. int n, mt[MAX_SIZE + 1][MAX_SIZE + 1], mt2[MAX_SIZE + 1][MAX_SIZE + 1];
  20. cin >> n;
  21. for (int i = 1; i <= n; ++i) {
  22. for (int j = 1; j <= n; ++j) {
  23. cin >> mt[i][j];
  24. }
  25. }
  26. for (int i = 1; i <= n; ++i) {
  27. for (int j = 1; j <= n; ++j) {
  28. cin >> mt2[i][j];
  29. }
  30. }
  31. newMatrix(n, mt, mt2);
  32. return 0;
  33. }
Success #stdin #stdout 0.01s 5292KB
stdin
3
2 2 2 
2 2 2 
2 2 2 
1 2 3
1 2 3
1 2 3
stdout
3 4 5 
3 4 5 
3 4 5