Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <conio.h>
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <ctime>
  5. using namespace std;
  6.  
  7. const int m = 10, n = 10;
  8. int tab[m][n];
  9. int sum = m * n;
  10.  
  11. void Rand_10x10_fill(int start, int finish)
  12. {
  13.     srand(time(NULL));
  14.     for (int i = 0; i < m; i++)
  15.     {
  16.         for (int j = 0; j < n; j++)
  17.         {
  18.             tab[i][j] = rand() % (finish - start + 1) + start;
  19.         }
  20.     }
  21. }
  22.  
  23. void sort_2d_matrix(int MyArray[m][n])
  24. {
  25.     for (int ir = 0; ir < m; ir++)
  26.     {
  27.         for (int ic = 0; ic < m; ic++)
  28.         {
  29.             for (int jr = 0; jr < n; jr++)
  30.             {
  31.                 for (int jc = 0; jc < n; jc++)
  32.                 {
  33.                     if (MyArray[ir][jr] > MyArray[ic][jc])
  34.                     {
  35.                         int temp = MyArray[ir][jr];
  36.                         MyArray[ir][jr] = MyArray[ic][jc];
  37.                         MyArray[ic][jc] = temp;
  38.                     }
  39.                 }
  40.             }
  41.         }
  42.     }
  43. }
  44.  
  45. void display_matrix() {
  46.     for (int i = 0; i < m; i++)
  47.     {
  48.         for (int j = 0; j < n; j++)
  49.         {
  50.             cout << " " << tab[i][j];
  51.         }
  52.         cout << endl;
  53.     }
  54. }
  55.  
  56. int main()
  57. {
  58.     //cin >> m >> n;
  59.     //srand(time(NULL));
  60.     Rand_10x10_fill(NULL, sum);
  61.     cout << endl;
  62.     cout << "macierz randomowa \n\n";
  63.     display_matrix();
  64.     cout << endl;
  65.     cout << "macierz odsortowana \n\n";
  66.     sort_2d_matrix(tab);
  67.     display_matrix();
  68.     cout << endl;
  69.     system("pause");
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement