#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
for(unsigned i=0; i<8; i+=2)
swap(a[i], a[i+1]);
for(unsigned i=0; i<10; i++)
cout << a[i] << " ";
system("pause");
return 0;
}
Результат работы программы
Следующий вариант
#include <iostream>
#include <algorithm>
#include <iterator>
int main(){
const int size(10);
int arr[size] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
std::cout << "Before: ";
std::copy(arr, arr + size, std::ostream_iterator<int>(std::cout, " "));
for ( int i = 2; i < size; i += 4 )
std::swap(arr[i], arr[i-2]);
std::cout << "\nAfter: ";
std::copy(arr, arr + size, std::ostream_iterator<int>(std::cout, " "));
return 0;