Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- using namespace std;
- void sort(int arr[], const int *size)
- {
- for (int i = *size -1; i >=0; i--)
- {
- int max = i;
- for (int j = i - 1; j >=0; j--)
- {
- if (arr[j] > arr[max])
- {
- max = j;
- }
- }
- int temp;
- temp = arr[i];
- arr[i] = arr[max];
- arr[max] = temp;
- }
- }
- int main()
- {
- setlocale(LC_ALL, "RUS");
- const int size = 20;
- srand(time(0));
- int A[size] = { 0 };
- cout << "Неотсортированные элементы: " << endl;
- for (int i = 0; i < size; i++)
- {
- A[i] = rand() % 100 + 1;
- cout << A[i] << " | ";
- }
- sort(A, &size);
- cout << endl << "Отсортированные элементы: " << endl;
- for (int i = 0; i < size; i++)
- {
- cout << A[i] << " | ";
- }
- cin.get();
- cin.ignore();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement