We can add, subtract, multiply and divide 2 matrices of multi-dimensions. For that, we take input from the user the number of rows, columns, first matrix elements and second matrix elements. Then we perform multiplication on the matrices entered by the user and store it in some other matrix.
In matrix addition, one row element of first matrix is individually added to corresponding column elements.
Flowchart for Matrix addition
Pseudocode for Matrix addition
Step 1: Start
Step 2: Declare matrix A[r][c];
and matrix B[r][c];
and matrix C[r][c]; rows= r columns= c
Step 3: Read r, c, p, A[][] and B[][]
Step 4: Declare variable i=0, j=0
Step 5: Repeat until i < r
5.1: Repeat until j < c
C[i][j]=A[i][j] + B[i][j]
Set j=j+1
5.2: Set i=i+1
Step 6: C is the required matrix
Step 7: Stop
In the above algorithm,
- We first define three matrices A, B, C and read their respective row and column numbers in variable r and c
- Read matrices A and B.
- First, start a loop for getting row elements of A and B
Secondly, inside it again start a loop for column of A and B
- Then, we store their corresponding addition by C[i][j]=A[i][j] + B[i][j] into C[i][j]