Advertisement
HyperSensualNarwhal

Sorting

Dec 23rd, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using std::cout;
  4. using std::cin;
  5. using std::endl;
  6.  
  7. void main()
  8. {
  9.  
  10.     const int size = 20;
  11.     int arr[size];
  12.    
  13.     for (int i = 0; i < size; i++)
  14.     {
  15.         arr[i] = (rand() % 100);
  16.         cout << arr[i] << "\t";
  17.     }
  18.  
  19.  
  20.     for (int i = 0; i < size; i++)
  21.     {
  22.         for (int j = 0; j < size; j++)
  23.         {
  24.             if (arr[j] < arr[j + 1])
  25.             {
  26.                 arr[j] = arr[j] + arr[j + 1];
  27.                 arr[j + 1] = arr[j] - arr[j + 1];
  28.                 arr[j] = arr[j] - arr[j + 1];
  29.             }
  30.         }
  31.     }
  32.  
  33.     cout << endl << endl;
  34.  
  35.     for (int i = 0; i < size; i++)
  36.     {
  37.         cout << arr[i] << "\t";
  38.     }
  39.  
  40.     cout << endl << endl;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement