Matrix Addition
Time limit1sMemory limit128 MB
Read two N by M integer matrices and print their element-wise sum.
- Level
Easy1 of 10
- Topics
- Matrix, Implementation
- Solved
- No attempts yet
Problem
You are given two integer matrices A and B, each of size N*M. Write a program that outputs the matrix formed by adding the entries in the same positions of A and B.
Input
The first line contains the matrix dimensions N and M. The next N lines contain matrix A, with M integers on each line. The following N lines contain matrix B, also with M integers on each line.
N and M are positive integers at most 100, and every matrix entry is an integer whose absolute value is at most 100.
Output
Print N lines, the matrix obtained by adding A and B. Each line must contain M entries of one row, separated by spaces.