MATADD - Editorial

Prerequisites: Matrix, Basic Math, Loop

Problem: This problem requires adding two matrices of the same size and printing the resultant matrix.

Solution Approach:

  • Addition: After inputting both matrices, element-wise addition is performed. For each corresponding element in matrices A and B, their sum is calculated and stored in a resultant matrix.

  • Output: The resultant matrix, obtained by adding the corresponding elements of matrices A and B, is printed. The elements are printed row by row, separated by space, and each row is printed on a new line.

Time Complexity: The time complexity of this solution is O(M * N) since it iterates through all elements of the matrices.

Space Complexity: The space complexity is O(M * N) to store the input matrices and the resultant matrix.