Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int n;
  7.     cout<<"enter the number of elements in the array ";
  8.     cin>>n;
  9.    
  10.     int a[n];
  11.    
  12.     for (int i = 0; i < n; i++) {
  13.         cin>>a[i];
  14.     }
  15.  
  16.    for (int i = 1; i < n; i += 2)
  17.     {
  18.         int t = a[i-1];
  19.         a[i-1] = a[i];
  20.         a[i] = t;
  21.     }
  22.  
  23.    for (int i = 0; i < n; i++){
  24.       cout << " " << a[i];
  25.    }
  26.    
  27.    cout << endl;
  28.  
  29.    return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement