fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes
  6. int arr[] = {13, 46, 24, 52, 20, 9};
  7. // int mine = INT_MAX;
  8. int index=-1;
  9. int mine = INT_MAX;
  10. for(int i=0;i<6;i++){
  11. for(int j=i;j<6;j++){
  12. if(arr[j]<mine)
  13. index = j,mine=min(mine,arr[j]);
  14. // mine = min(mine,arr[j]);
  15. }
  16. // cout<<"mine is "<<mine<<endl;
  17. // cout<<
  18. swap(arr[index],arr[i]);
  19. // cout<<"after swap arr[i] "<<arr[i]<<" and arr[5] "<<arr[5]<<endl;
  20. }
  21. for(int i=0;i<6;i++){
  22. cout<<arr[i]<<" ";
  23. }
  24. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
9 13 46 24 52 20