fork(3) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin >> n;
  7. int arr[n];
  8. for(int i = 0; i < n; i++){
  9. cin >> arr[i];
  10. }
  11. for(int i = 1; i < n; i+=2){
  12. int q = arr[i];
  13. arr[i] = arr[i-1];
  14. arr[i-1] = q;
  15. }
  16. for(int i = 0; i < n; i++){
  17. cout << arr[i] << " ";
  18. }
  19. return 0;
  20. }
Success #stdin #stdout 0s 4392KB
stdin
7
3 5 -7 7 5 -9 -4 
stdout
5 3 7 -7 -9 5 -4