0

Program adding two matrix

matrix

27th Feb 2017, 12:13 PM
Satyam Jaiswal
Satyam Jaiswal - avatar
2 Answers
+ 6
First you have to check they have the same dimensions (length for columns and rows), create a new matrix for the sum and then use one for loop for the rows and another for the columns inside it, then you just set each sum value of "m1[i,j]+m2[i,j]"
27th Feb 2017, 12:50 PM
C.E.
C.E. - avatar
+ 1
int m1[][]=new int[n][m]; int m2[][]=new int[n][m]; int a[][]=new int[n][m]; for(int I=0;I<n;I++) { for(int j=0;j<m;j++) { a[I][j]=m1[I][j]+m2[I][j]; } } //print matrix a[][]
27th Feb 2017, 7:20 PM
Vaibhav Tandon
Vaibhav Tandon - avatar