fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. void selection(int n, int ara[])
  4. {
  5. for(int i = 0; i < n-1; i++)
  6. {
  7. for(int j = i+1; j < n; j++)
  8. {
  9. if(ara[i] > ara[j])
  10. {
  11. swap(ara[i], ara[j]);
  12. }
  13. for(int i = 0; i < n; i++)
  14. {
  15. cout<<ara[i]<<" ";
  16. }
  17. cout<<endl;
  18. }
  19. }
  20. }
  21.  
  22. int main()
  23. {
  24. int n;
  25. cin>>n;
  26. int ara[n];
  27. for(int i = 0; i < n; i++)
  28. {
  29. cin>>ara[i];
  30. }
  31.  
  32. selection(n, ara);
  33.  
  34.  
  35.  
  36. }
  37.  
Success #stdin #stdout 0.01s 5320KB
stdin
5
5 8 6 1 7
stdout
5 8 6 1 7 
5 8 6 1 7 
1 8 6 5 7 
1 8 6 5 7 
1 6 8 5 7 
1 5 8 6 7 
1 5 8 6 7 
1 5 6 8 7 
1 5 6 8 7 
1 5 6 7 8