Advertisement
Guest User

mnozenie macierzy

a guest
Dec 5th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void elementy (int tab[][100], int m, int n)
  6. {
  7.     for (int x=0; x<m; x++)
  8.     {
  9.         for (int y=0; y<n; y++)
  10.         {
  11.             cout << "Podaj wartosc tab[" << x+1 << "][" << y+1 << "]: ";
  12.             cin >> tab[x][y];
  13.         }
  14.     }
  15. }
  16.  
  17. void zerowanie(int tab[][100])
  18. {
  19.     for (int x=0; x<100; x++)
  20.     {
  21.         for (int y=0; y<100; y++)
  22.         {
  23.             tab[x][y]=0;
  24.         }
  25.     }
  26. }
  27.  
  28. void iloczyn(int tab1[][100], int tab2[][100], int tab3[][100], int a, int b, int c, int d)
  29. {
  30.     for(int z=0; z>a; z++)
  31.     {
  32.         for(int y=0; y<d; y++)
  33.         {
  34.             for(int x=0; x<b; x++)
  35.             {
  36.                 tab3[z][y]=tab3[z][y]+(tab1[z][x]*tab2[x][y]);
  37.             }
  38.         }
  39.     }
  40. }
  41.  
  42. void wyniki(int tab[][100], int a, int d)
  43. {
  44.     for(int x=0; x<a; x++)
  45.     {
  46.         for(int y=0; y<d; y++)
  47.         {
  48.             cout << "tab[" << y+1 << "][" << x+1 << "]=" << tab[y][x] << endl;
  49.         }
  50.     }
  51. }
  52.  
  53. int main()
  54. {
  55.     int tab1[100][100], tab2[100][100], tab3[100][100], a, b, c, d;
  56.     cout << "Podaj ilosc wierszy pierwszej macierzy: ";
  57.     cin >> a;
  58.     cout << "Podaj ilosc kolumn pierwszej macierzy: ";
  59.     cin >> b;
  60.     elementy(tab1, a, b);
  61.     c=b;
  62.     cout << "Podaj ilosc kolumn drugiej macierzy: ";
  63.     cin >> d;
  64.     elementy(tab2, c, d);
  65.     zerowanie(tab3);
  66.     iloczyn(tab1, tab2, tab3, a, b, c, d);
  67.     wyniki(tab3, a, d);
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement