File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed
Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < iostream>
2+ using namespace std ;
3+
4+ int main (){
5+
6+ int r1, c1;
7+ cout << " Enter the order of the first matrix: " ;
8+ cin >> r1 >> c1;
9+ int r2, c2;
10+ cout << " Enter the order of the second matrix: " ;
11+ cin >> r2 >> c2;
12+ while (c1 != r2){
13+ cout << " Enter order again" << " \n " ;
14+ cout << " Enter the order of the first matrix: " ;
15+ cin >> r1 >> c1;
16+ cout << " Enter the order of the second matrix: " ;
17+ cin >> r2 >> c2;
18+ }
19+ int arr1[r1][c1], arr2[r2][c2], arr3[r1][c2];
20+ cout << " Enter the elements of the first matrix: " << " \n " ;
21+ for (int i=0 ;i<r1;i++)
22+ {
23+ for (int j=0 ;j<c1;j++)
24+ {
25+ cin >> arr1[i][j];
26+ }
27+ }
28+ cout << " Enter the elements of the second matrix: " << " \n " ;
29+ for (int i=0 ;i<r2;i++)
30+ {
31+ for (int j=0 ;j<c2;j++)
32+ {
33+ cin >> arr2[i][j];
34+ }
35+ }
36+ for (int i=0 ;i<r1;i++)
37+ {
38+ for (int j=0 ;j<c2;j++)
39+ {
40+ arr3[i][j] = 0 ;
41+ for (int k=0 ;k<c1;k++)
42+ {
43+ arr3[i][j] += arr1[i][k]*arr2[k][j];
44+ }
45+ }
46+ }
47+ cout << " The resultant matrix is: " << " \n " ;
48+ for (int i=0 ;i<r1;i++)
49+ {
50+ for (int j=0 ;j<c2;j++)
51+ {
52+ cout << arr3[i][j] << " " ;
53+ }
54+ cout << " \n " ;
55+ }
56+ return 0 ;
57+ }
You can’t perform that action at this time.
0 commit comments