#C2328. Matrix Addition
Matrix Addition
Matrix Addition
You are given two n × n matrices. Your task is to compute the element-wise sum of these matrices. For each element \(a_{ij}\) in the first matrix and \(b_{ij}\) in the second matrix, the resulting matrix \(c\) should satisfy:
\( c_{ij} = a_{ij} + b_{ij} \)
The input is provided via standard input (stdin) and the output should be printed to standard output (stdout). Each matrix row is given on a separate line with space-separated integers. Ensure that your solution correctly reads the input, computes the matrix addition, and prints the resulting matrix in the required format.
inputFormat
The input is read from stdin and has the following format:
n row1_of_matrix1 row2_of_matrix1 ... (n rows total) row1_of_matrix2 row2_of_matrix2 ... (n rows total)
Where:
n
is an integer denoting the dimensions of the matrices.- Each
row
consists ofn
space-separated integers.
outputFormat
The output should be printed to stdout. It consists of n
lines where each line contains n
space-separated integers representing the sum of the corresponding rows of the two input matrices.
2
1 2
3 4
5 6
7 8
6 8
10 12
</p>