Advertisement
AlexandruFilipescu

Prof Constantinescu Matrice inmultita(Matrix multiplication)

May 23rd, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5.  
  6. int main() {
  7.     int  *q, *p, *r, k,y,l,c,total, matrice[100][100];
  8.     cout << "Introduceti liniile si coloanele matricelor: ";
  9.     cin >> l >> c;
  10.  
  11.     total = l * c;
  12.    
  13.     q = new int(total);
  14.     p = new int(total);
  15.     r = new int(total);
  16.  
  17.    
  18.     cout << "Introduceti elementele  matricii 1: " << endl;
  19.  
  20.     for (int i = 0; i < total; i++) {
  21.             cin >> q[i];
  22.     }
  23.  
  24.     cout << "Introduceti elementele  matricii 2: " << endl;
  25.  
  26.  
  27.     for (int i = 0; i < l; i++) {
  28.         for (int j = 0; j < c; j++) {
  29.             cin >> matrice[i][j];
  30.         }
  31.     }
  32.  
  33.     k = 0;
  34.     for (int i = 0; i < l; i++) {
  35.         for (int j = 0; j < c; j++) {
  36.             p[k] = matrice[j][i];
  37.             k++;
  38.         }
  39.     }
  40.  
  41.     k = 0;
  42.     y = 0;
  43.     for (int i = 0; i < total; i++) {
  44.         if (i < sqrt(total)) {
  45.             k = 0;
  46.         }
  47.         else {
  48.             k = 2;
  49.         }
  50.  
  51.         if (i%2==0) {
  52.             y = 0;
  53.         } else {
  54.             y = 2;
  55.         }
  56.  
  57.         r[i] = q[k] * p[y];
  58.     }
  59.  
  60.     k = 0;
  61.     y = 0;
  62.     for (int i = 0; i < total; i++) {
  63.         if (i < sqrt(total)) {
  64.             k = 1;
  65.         } else {
  66.             k = 3;
  67.         }
  68.  
  69.         if (i%2==0) {
  70.             y = 1;
  71.         }  else {
  72.             y = 3;
  73.         }
  74.  
  75.         r[i] += q[k] * p[y];
  76.  
  77.     }
  78.  
  79.     for (int i = 0; i < total; i++)
  80.     {
  81.         cout << r[i] << " ";
  82.     }
  83.  
  84.  
  85.     system("pause");
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement