MeehoweCK

Untitled

Mar 15th, 2021
726
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. // zadanie 7. (dwuwymiarowe)
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <ctime>
  5.  
  6. using namespace std;
  7.  
  8. int** utworz1(const unsigned n, const unsigned m)
  9. {
  10.     int** tablica = new int*[n];
  11.     for(unsigned i = 0; i < n; ++i)
  12.     {
  13.         tablica[i] = new int[m];
  14.         for(unsigned j = 0; j < m; ++j)
  15.             tablica[i][j] = rand() % 11;
  16.     }
  17.     return tablica;
  18. }
  19.  
  20. void wypisz(int** tab, const unsigned n, const unsigned k)
  21. {
  22.     for(unsigned i = 0; i < n; ++i)
  23.     {
  24.         for(unsigned j = 0; j < k; ++j)
  25.             cout << tab[i][j] << '\t';
  26.         cout << endl;
  27.     }
  28. }
  29.  
  30. bool iloczyn_macierzy(int** macierz1, int** macierz2, const unsigned w1, const unsigned k1, const unsigned w2, const unsigned k2, int**& wynik)
  31. {
  32.     if(k1 != w2)
  33.         return false;
  34.     // tworzymy macierz o wymiarach w1 na k2
  35.     int suma;
  36.     wynik = utworz1(w1, k2);
  37.     for(unsigned i = 0; i < w1; ++i)
  38.         for(unsigned j = 0; j < k2; ++j)
  39.         {
  40.             suma = 0;
  41.             for(unsigned x = 0; x < k1; ++x)
  42.                 suma += macierz1[i][x] * macierz2[x][j];
  43.             wynik[i][j] = suma;
  44.         }
  45.     return true;
  46. }
  47.  
  48. int main()
  49. {
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment