1- #include < iostream>
2- using namespace std ;
3- int main (){
4- // WAP in C++ to multiply matrix
5- int a[10 ][10 ],b[10 ][10 ],mul[10 ][10 ],r,c,i,j,k,p=1 ,q=1 ;
6- cout<<" Enter the number of row:" <<endl;
7- cin>>r;
8- cout<<" Enter the number of column:" <<endl;
9- cin>>c;
10- cout<<" Enter the first matrix element" <<endl;
11- for (i=0 ;i<r;i++){
12- for (j=0 ;j<c;j++){
13- cout<<" Element" <<p<<" :" <<endl;
14- cin>>a[i][j]; p++; } }
15- cout<<" Enter the second matrix element" <<endl;
16- for (i=0 ;i<r;i++) {
17- for (j=0 ;j<c;j++){
18- cout<<" Element" <<q<<" :" <<endl;
19- cin>>b[i][j]; q++; }
20- }
21- cout<<" Multiplication of the matrix:" <<endl;
22- for (i=0 ;i<r;i++){
23- for (j=0 ;j<c;j++) {
24- mul[i][j]=0 ;
25- for (k=0 ;k<c;k++) {
26- mul[i][j]+=a[i][k]*b[k][j];
27- } } }
28- for (i=0 ;i<r;i++){
29- for (j=0 ;j<c;j++){
30- cout<<mul[i][j]<<" \t " ; }
31- cout<<" \n " ; }
32- return 0 ; }
1+ #include < iostream>
2+ using namespace std ;
3+ int main ()
4+ {
5+ // WAP in C++ to multiply matrix
6+ int a[10 ][10 ], b[10 ][10 ], mul[10 ][10 ], r, c, i, j, k, p = 1 , q = 1 ;
7+ cout << " Enter the number of row:" << endl;
8+ cin >> r;
9+ cout << " Enter the number of column:" << endl;
10+ cin >> c;
11+ cout << " Enter the first matrix element" << endl;
12+ for (i = 0 ; i < r; i++)
13+ {
14+ for (j = 0 ; j < c; j++)
15+ {
16+ cout << " Element" << p << " :" << endl;
17+ cin >> a[i][j];
18+ p++;
19+ }
20+ }
21+ cout << " Enter the second matrix element" << endl;
22+ for (i = 0 ; i < r; i++)
23+ {
24+ for (j = 0 ; j < c; j++)
25+ {
26+ cout << " Element" << q << " :" << endl;
27+ cin >> b[i][j];
28+ q++;
29+ }
30+ }
31+ cout << " Multiplication of the matrix:" << endl;
32+ for (i = 0 ; i < r; i++)
33+ {
34+ for (j = 0 ; j < c; j++)
35+ {
36+ mul[i][j] = 0 ;
37+ for (k = 0 ; k < c; k++)
38+ {
39+ mul[i][j] += a[i][k] * b[k][j];
40+ }
41+ }
42+ }
43+ for (i = 0 ; i < r; i++)
44+ {
45+ for (j = 0 ; j < c; j++)
46+ {
47+ cout << mul[i][j] << " \t " ;
48+ }
49+ cout << " \n " ;
50+ }
51+ return 0 ;
52+ }
0 commit comments