Example 70: Addition of Matrices
Learn how to add two matrices.
We'll cover the following
Problem
Write a program to obtain the sum of two 3 x 3 matrices.
The function takes in three 2-D arrays as parameters, where the first two arrays represent the original matrices, and in the third array, you need to store the result of addition.
Example
Input (Matrix 1, Matrix 2) | Output (Matrix 3) |
---|---|
1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 |
3 3 3 3 3 3 3 3 3 |
1 2 3 1 2 3 1 2 3 2 3 4 2 3 4 2 3 4 |
3 5 7 3 5 7 3 5 7 |
Demonstration
Get hands-on with 1400+ tech skills courses.