fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void selection_sort(int arr[], int n)
  5. {
  6. for (int i = 0; i < n; i++)
  7. {
  8. int ind = i;
  9.  
  10. for (int j = i + 1; j < n; j++)
  11. {
  12. if (arr[j] > arr[ind])
  13. {
  14. ind = j;
  15. }
  16. }
  17.  
  18. swap(arr[ind], arr[i]);
  19. }
  20. }
  21.  
  22. int main()
  23. {
  24. int n;
  25. cin >> n;
  26.  
  27. int arr[100];
  28.  
  29. for (int i = 0; i < n; i++)
  30. {
  31. cin >> arr[i];
  32. }
  33.  
  34. selection_sort(arr, n);
  35.  
  36. for (int i = 0; i < n; i++)
  37. {
  38. cout << arr[i] << " ";
  39. }
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty