Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 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 *wierszy = &m, *columny = &n;
  9. int tab[m][n];
  10. int sum = m * n;
  11.  
  12. ////////////////
  13. /*
  14. void create_matrix(int i, int j)
  15. {
  16.     int tab[i][j];
  17. }
  18. */
  19. void Rand_10x10_fill(int start, int finish)
  20. {
  21.     for (int i = 0; i < m; i++)
  22.     {
  23.         for (int j = 0; j < n; j++)
  24.         {
  25.             tab[i][j] = rand() % (finish - start + 1) + start;
  26.         }
  27.     }
  28. }
  29. /*
  30. void sort()
  31. {
  32.     for (int i = 0; i < 10; i++)
  33.     {
  34.         for (int j = 0; j < 10; j++)
  35.         {
  36.             int tmp = tab[i];
  37.             if (tab[j] > tmp)
  38.             {
  39.                 tab[i] = tab[j];
  40.                 tab[j] = tmp;
  41.             }
  42.         }
  43.     }
  44. }
  45. */
  46. void sort(int MyArray[m][n])
  47. {
  48.     for (int ir = 0; ir < m; ir++)
  49.     {
  50.         for (int ic = 0; ic < m; ic++)
  51.         {
  52.             for (int jr = 0; jr < n; jr++)
  53.             {
  54.                 for (int jc = 0; jc < n; jc++)
  55.                 {
  56.                     if (MyArray[ir][jr] > MyArray[ic][jc])
  57.                     {
  58.                         int temp = MyArray[ir][jr];
  59.                         MyArray[ir][jr] = MyArray[ic][jc];
  60.                         MyArray[ic][jc] = temp;
  61.                     }
  62.                 }
  63.             }
  64.         }
  65.     }
  66. }
  67.  
  68. void display_matrix() {
  69.     for (int i = 0; i < m; i++)
  70.     {
  71.         for (int j = 0; j < n; j++)
  72.         {
  73.             cout << " " << tab[i][j];
  74.         }
  75.         cout << endl;
  76.     }
  77. }
  78.  
  79. /*
  80. for (int i=0; i<size; i++) {
  81.     for (int j=0; j<size; j++)
  82.         cout << " " << MAS[i][j];
  83.     cout << endl; }
  84. */
  85.  
  86. int main()
  87. {
  88.     //cin >> m >> n;
  89.     srand(time(NULL));
  90.     Rand_10x10_fill(NULL, sum);
  91.     cout << endl;
  92.     cout << "macierz randomowa \n\n";
  93.     display_matrix();
  94.     cout << endl;
  95.     cout << "macierz odsortowana \n\n";
  96.     sort(tab);
  97.     display_matrix();
  98.     cout << endl;
  99.     system("pause");
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement