Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. using namespace std;
  4.  
  5. void sort(int arr[], const int *size)
  6. {
  7.     for (int i = *size -1; i >=0; i--)
  8.     {
  9.         int max = i;
  10.  
  11.         for (int j = i - 1; j >=0; j--)
  12.         {
  13.             if (arr[j] > arr[max])
  14.             {
  15.                 max = j;
  16.             }
  17.         }
  18.         int temp;
  19.         temp = arr[i];
  20.         arr[i] = arr[max];
  21.         arr[max] = temp;
  22.     }
  23. }
  24.  
  25. int main()
  26. {
  27.     setlocale(LC_ALL, "RUS");
  28.     const int size = 20;
  29.     srand(time(0));
  30.     int A[size] = { 0 };
  31.     cout << "Неотсортированные элементы: " << endl;
  32.     for (int i = 0; i < size; i++)
  33.     {
  34.         A[i] = rand() % 100 + 1;
  35.         cout << A[i] << " | ";
  36.     }
  37.     sort(A, &size);
  38.     cout << endl << "Отсортированные элементы: " << endl;
  39.     for (int i = 0; i < size; i++)
  40.     {
  41.         cout << A[i] << " | ";
  42.     }
  43.     cin.get();
  44.     cin.ignore();
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement