In matrix Subtraction, one row element of first matrix is individually subtracted with corresponding column elements i.e. for 1st element at Position[0,0], the subtraction of first Matrix's Position[0,0] will be subtracted with Second Matrix's Position[0,0]. Let's see this in Mathematical equation, if
A and B are the Matrix entered by user and we are storing subtraction in Matrix C, then

for Position[0,0]: C[0,0]=A[0,0]-B[0,0]
for Position[0,1]: C[0,1]=A[0,1]-B[0,1]
Similarly we perform subtraction of each element for corresponding Position.

## Flowchart for Matrix Subtraction

## Pseudocode for Matrix Subtraction

Step 1: Start
Step 2: Declare matrix A[r][c] // Matrix 1;
and matrix B[r][c] // Matrix 2;
and matrix C[r][c]; r= no. of rows, c= no. of columns
Step 3: Read r, c, 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 after subtraction
Step 7: Stop
In the above algorithm,

- We first define 3 matrices A, B, C and read their respective row and column numbers in variable r and c
- Read matrices A and B (Here Matrix B will be subtracted from Matrix A).
- 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 subtraction by formula: C[i][j]=A[i][j] - B[i][j].
- When the loop ends for all rows and columns, the result will be stored in Matrix C[i][j]

#### Recommended Posts:

Our Quiz prepared by Experts Helps you identify your knowledge in Algorithms. Everyone should atleast attempt this Quiz Once.