Program in Java for Sum of Matrices

Sum of Matrices in Java :

Sum of matrix is the matrix whose each cell contains the sum of the values of the given matrix in their corresponding cell.

e.g.

A(3×3)=[ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]

B(3×3)=[ [11, 22, 33], [44, 55, 66], [77, 88, 99] ]

A+B(3×3)=[ [12, 24, 36], [48, 60, 72], [84, 96, 108] ]

Below is the program to input two matrices and produce a resultant matrix which carries their Sum.

Source Code :

Output :

Enter the size of matrices (nxm) :
2
2
Input Matrix 1 :
25
12
13
1
Input Matrix 2 :
23
56
4
0
Sum of the matrices is :
48  68
17  1

Leave a Reply

Your email address will not be published. Required fields are marked *