Advertisement
Guest User

Untitled

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