fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int tab[] = {1,2,3,4,5,6,7};
  6.  
  7. for (int i = 0; i < 7; i+= 2) {
  8. int tmp = tab[i];
  9. tab[i] = tab[i+1];
  10. tab[i+1] = tmp;
  11. }
  12.  
  13. for (int i = 0; i < 7; i++) {
  14. cout << tab[i] << " ";
  15. }
  16.  
  17. return 0;
  18. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
2 1 4 3 6 5 1