### Difference of two matrices in c ++

An item in a matrix is called an entry or an element. The example has entries 1, 9, 13, 20, 55, and 6. Entries are often denoted by a variable with two subscripts. Thus in the matrix above, a2,1 = 20. Matrices of the same size can be added and subtracted entry-wise and matrices of compatible sizes can be multiplied. These operations have many of the properties of ordinary arithmetic, except that matrix multiplication is not commutative, that is, AB and BA are not equal in general.

Algorithm:
Rule: Difference of two matrixes is only possible if both matrixes are of same size.
Suppose two matrixes A and B is of same size m X n
difference of two matrixes is defined as
(A - B)ij = Aij - Bij
Where 1 ≤ i ≤ m and 1 ≤ j ≤ n

For example:
Suppose two matrixes A and B of size of 2 X 2 is as follow:

A = 5 10                    B = 3 8
8  6                           2 9

A-B = 5-3        10-8
8-2          6-9

= 2       2
6      -3

C ++programming code :

Output of program :

Enter the number of Rows of Matrix 1 : 3

Enter the number of Columns of Matrix 1 : 2
Enter the Element a[0][0] : 8
Enter the Element a[0][1] : 9
Enter the Element a[1][0] : 6
Enter the Element a[1][1] : 7
Enter the Element a[2][0] : 4
Enter the Element a[2][1] : 5

Enter the number of Rows of Matrix 2 : 3

Enter the number of Columns of Matrix 2 : 2
Enter the Element b[0][0] : 1
Enter the Element b[0][1] : 2
Enter the Element b[1][0] : 3
Enter the Element b[1][1] : 1
Enter the Element b[2][0] : 2
Enter the Element b[2][1] : 5

The Subtraction of two Matrices is :
7       7
3       6
2       0

Date - 1/25/2013-@author Y.ACHCHUTHAN -cpp90.blogspot.com
Press any key to continue . . .