
Sanhita M. answered 07/25/16
Tutor
4.7
(11)
Mathematics and Geology
Here's the algorithm, it will fit to any programming language if syntax is correct
1. Define variables r, c, /* r and c stands for number of rows and columns respectively of two different matrices */
Define variable i, j /* the loop counters */
2. Define 2-D strings Mat1 [r][c], Mat2 [r][c] /*The matrices to be added*/
Also Define 2-D string Mat3[r][c] /* The resultant matrix*/
4. Define variable n /* For taking input of Each element of matrices */
5. Input r, c
6. Loop i=1 to r
Loop j=1 to c
Input Mat1 [r][c]
j=j+1
i=i+1
7. Output Mat1 [r][c]
8. Loop i=1 to r
Loop j=1 to c
Input Mat2 [r][c]
j=j+1
i=i+1
9. Output Mat2 [r][c]
Loop j=1 to c
Input Mat2 [r][c]
j=j+1
i=i+1
9. Output Mat2 [r][c]
10. Loop i=1 to r
Loop j=1 to c
Mat3 [r][c]=Mat1 [r][c]+Mat2 [r][c] /*Matrix Addition */
j=j+1
i=i+1
11. Output Mat3 [r][c]
Loop j=1 to c
Mat3 [r][c]=Mat1 [r][c]+Mat2 [r][c] /*Matrix Addition */
j=j+1
i=i+1
11. Output Mat3 [r][c]
12. Loop i=1 to r
Loop j=1 to c
Mat3 [r][c]=Mat1 [r][c]+Mat2 [c][r] /*Matrix Addition */
j=j+1
i=i+1
13. Output Mat3 [r][c]
Loop j=1 to c
Mat3 [r][c]=Mat1 [r][c]+Mat2 [c][r] /*Matrix Addition */
j=j+1
i=i+1
13. Output Mat3 [r][c]
14. End