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