Advertisement
Dani_info

inmultirea matricilor

May 20th, 2018
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. /*
  6.     1 0       1 0 2 0                 1 1 2 0
  7.     2 1       0 1 1 0      =>         2 1 5 0
  8.     0 1                               0 1 1 0
  9.  
  10. */
  11. int main()
  12. {
  13.     //int a[3][2], b[2][4],
  14.     int m, n, p;
  15.     cout<<"Prima matrice:"<<endl;
  16.     cout<<"m="; cin>>m;
  17.     cout<<"n="; cin>>n;
  18.     int a[m][n];
  19.     for (int i=0; i<m; i++){
  20.         for (int j=0; j<n; j++)
  21.             cin>>a[i][j];
  22.     }
  23.     cout<<"A doua matrice:"<<endl;
  24.     cout<<"p="; cin>>p;
  25.     int b[n][p];
  26.     for (int i=0; i<n; i++){
  27.         for (int j=0; j<p; j++)
  28.             cin>>b[i][j];
  29.     }
  30.     int c[m][p];
  31.     for (int i=0; i<m; i++){
  32.         for (int j=0; j<p; j++){
  33.             c[i][j]=0;
  34.             for (int k=0; k<n; k++){
  35.                 c[i][j]+=(a[i][k]*b[k][j]);
  36.             }
  37.         }
  38.     }
  39.     cout<<"=============="<<endl;
  40.     for (int i=0; i<m; i++){
  41.         for (int j=0; j<p; j++)
  42.             cout<<c[i][j]<<" ";
  43.         cout<<endl;
  44.     }
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement