6. Assignment 7
WAP to find the product of given matrix.
Input: Read no.of rows and columns for 2 arrays and read the
array elements for the Matrix A and B
7. Assignment 7
WAP to find the product of given matrix.
Input: Read no.of rows and columns for 2 arrays and read the
array elements for the Matrix A and B
Output:
8. Assignment 7
WAP to find the product of given matrix.
Input: Read no.of rows and columns for 2 arrays and read the
array elements for the Matrix A and B
Output: Print product for matrix A with matrix B.
12. Assignment 7
Example 1:-
Step1 : Read ‘row’ and ‘col’ for matrix A.
row1 = 3 , col1 = 3
Step2 : Read the array elements for matrix A.
13. Assignment 7
Example 1:-
Step1 : Read ‘row’ and ‘col’ for matrix A.
row1 = 3 , col1 = 3
Step2 : Read the array elements for matrix A.
1 2 3
1 2 3
1 2 3
16. Assignment 7
Example 1:-
Step3 : Read ‘row’ and ‘col’ for matrix B.
row2 = 3 , col2 = 3
Step4 : Read the array elements for matrix B.
17. Assignment 7
Example 1:-
Step3 : Read ‘row’ and ‘col’ for matrix B.
row2 = 3 , col2 = 3
Step4 : Read the array elements for matrix B.
1 1 1
2 2 2
3 3 3
20. Assignment 7
Example 1:-
Step5 : Calculate the product of matrix A and B.
Check (col1 == row2)
1 2 3 x 1 1 1 =
1 2 3 x 2 2 2 =
1 2 3 x 3 3 3 =
21. Assignment 7
Example 1:-
Step5 : Calculate the product of matrix A and B.
Check (col1 == row2)
1 2 3 x 1 1 1 = 14
1 2 3 x 2 2 2 =
1 2 3 x 3 3 3 =
22. Assignment 7
Example 1:-
Step5 : Calculate the product of matrix A and B.
Check (col1 == row2)
1 2 3 x 1 1 1 = 14 14
1 2 3 x 2 2 2 =
1 2 3 x 3 3 3 =
23. Assignment 7
Example 1:-
Step5 : Calculate the product of matrix A and B.
Check (col1 == row2)
1 2 3 x 1 1 1 = 14 14 14
1 2 3 x 2 2 2 =
1 2 3 x 3 3 3 =
24. Assignment 7
Example 1:-
Step5 : Calculate the product of matrix A and B.
Check (col1 == row2)
1 2 3 x 1 1 1 = 14 14 14
1 2 3 x 2 2 2 = 14
1 2 3 x 3 3 3 =
25. Assignment 7
Example 1:-
Step5 : Calculate the product of matrix A and B.
Check (col1 == row2)
1 2 3 x 1 1 1 = 14 14 14
1 2 3 x 2 2 2 = 14 14
1 2 3 x 3 3 3 =
26. Assignment 7
Example 1:-
Step5 : Calculate the product of matrix A and B.
Check (col1 == row2)
1 2 3 x 1 1 1 = 14 14 14
1 2 3 x 2 2 2 = 14 14 14
1 2 3 x 3 3 3 =
27. Assignment 7
Example 1:-
Step5 : Calculate the product of matrix A and B.
Check (col1 == row2)
1 2 3 x 1 1 1 = 14 14 14
1 2 3 x 2 2 2 = 14 14 14
1 2 3 x 3 3 3 = 14
28. Assignment 7
Example 1:-
Step5 : Calculate the product of matrix A and B.
Check (col1 == row2)
1 2 3 x 1 1 1 = 14 14 14
1 2 3 x 2 2 2 = 14 14 14
1 2 3 x 3 3 3 = 14 14
29. Assignment 7
Example 1:-
Step5 : Calculate the product of matrix A and B.
Check (col1 == row2)
1 2 3 x 1 1 1 = 14 14 14
1 2 3 x 2 2 2 = 14 14 14
1 2 3 x 3 3 3 = 14 14 14
30. Assignment 7
Example 2:-
Step1 : Read ‘row’ and ‘col’ for matrix A.
row1 = 3 , col1 = 2
Step2 : Read the array elements for matrix A.
4 1
7 6
9 2
31. Assignment 7
Example 2:-
Step3 : Read ‘row’ and ‘col’ for matrix B.
row2 = 3 , col2 = 2
Step4 : Read the array elements for matrix B.
4 1
6 3
3 8
32. Assignment 7
Example 2:-
In this example, row1 = 3, col1 = 2
row2 = 3, col2 = 2
Here, row1 ≠ col2 and also row2 ≠ col1. So matrix
multiplication is not possible in this case.