Explanation
In this program, we need to subtract two matrices and print the resulting matrix.
Subtraction of two matrices:
Matrix B can be subtracted from matrix A or vice versa if and only if they have same dimensions that are, the same number of rows and columns. It is not possible to subtract a 2 × 3 matrix from a 3 × 2 matrix. Subtraction of two matrices can be performed by subtracting their corresponding elements as
(A - B)ij = Aij - Bij

Subtraction of two matrices can be performed by looping through the first and second matrix. Calculating the difference between their corresponding elements and store the result in the third matrix.
Algorithm
- Declare and initialize two two-dimensional arrays a and b.
- Calculate the number of rows and columns present in the array a (as dimensions of both the arrays are same) and store it in variables rows and cols respectively.
- Declare another array diff with dimensions present in rows and columns.
- Loop through the arrays a and b, calculate the difference between the corresponding elements
e.g a11 - b11 = diff11
- Display the elements of array diff.
Input:
Matrix a = [4, 5, 6]
[3, 4, 1]
[1, 2, 3]
Matrix b = [2, 0, 3]
[2, 3, 1]
[1, 1, 1]
Output:
Subtraction of two matrices: [2 5 3]
[1 1 0]
[0 1 2]
Python
Output:
C
Output:
JAVA
Output:
C#
Output:
PHP
Output: