fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int a[] = {5, 2, 9, 1, 6, 3};
  6. int n = 6;
  7.  
  8. for(int i = 0; i < n-1; i++){
  9. int minPos = i;
  10. for(int j = i+1; j < n; j++){
  11. if(a[j] < a[minPos])
  12. minPos = j;
  13. }
  14. swap(a[i], a[minPos]);
  15. }
  16.  
  17. for(int i = 0; i < n; i++)
  18. cout << a[i] << " ";
  19. }
  20.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
1 2 3 5 6 9