fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, m;
  6.  
  7.  
  8. cin >> n;
  9.  
  10. cin >> m;
  11.  
  12.  
  13. if (n <= 0 || n > 5 || m <= 0 || m > 5) {
  14.  
  15. return 1;
  16. }
  17.  
  18. int matrix1[5][5], matrix2[5][5];
  19. float avg[5][5];
  20.  
  21.  
  22. for (int i = 0; i < n; i++) {
  23. for (int j = 0; j < m; j++) {
  24. cin >> matrix1[i][j];
  25. }
  26. }
  27.  
  28.  
  29. for (int i = 0; i < n; i++) {
  30. for (int j = 0; j < m; j++) {
  31. cin >> matrix2[i][j];
  32. }
  33. }
  34.  
  35.  
  36. for (int i = 0; i < n; i++) {
  37. for (int j = 0; j < m; j++) {
  38. avg[i][j] = (matrix1[i][j] + matrix2[i][j]) / 2.0;
  39. }
  40. }
  41.  
  42.  
  43. for (int i = 0; i < n; i++) {
  44. for (int j = 0; j < m; j++) {
  45. cout << avg[i][j] << " ";
  46. }
  47. cout << endl;
  48. }
  49.  
  50. return 0;
  51. }
Success #stdin #stdout 0.02s 25904KB
stdin
Standard input is empty
stdout
#include <iostream>
using namespace std;

int main() {
    int n, m;

   
    cin >> n;
   
    cin >> m;

   
    if (n <= 0 || n > 5 || m <= 0 || m > 5) {
      
        return 1;
    }

    int matrix1[5][5], matrix2[5][5];
    float avg[5][5];

   
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> matrix1[i][j];
        }
    }

   
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> matrix2[i][j];
        }
    }

   
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            avg[i][j] = (matrix1[i][j] + matrix2[i][j]) / 2.0;
        }
    }

   
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cout << avg[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}