Competitive Programming Solutions

GitHub
back to dashboard

N. Sum of a Matrix

Codeforces - Sheet #7 (Recursion) · limit: 1s · memory: 256MB · view on codeforces

input

2 3
1 2 3
4 5 6
1 3 5
7 9 11

output

2 5 8
11 14 17
Main.java
static void solve() {

        // Write your solution here
        int m = in.nextInt();
        int n = in.nextInt();
        
        int[][] a = new int[m][n];
        int[][] b = new int[m][n];

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                a[i][j] = in.nextInt();
            }
        }

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                b[i][j] = in.nextInt();
            }
        }

        int[][] c = new int[m][n];

        summation(a, b, c, 0, 0); 

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                out.print(c[i][j] + " ");
            }
            out.println();
        }
    }