OBJECTIVE
We have to shuffle the elements of an array such that each element, starting from the beginning of array is interchanged with its successor element.
// C++ Program to shuffle elements in pairs
#include <iostream>
#define N 10
using namespace std;
int main()
{
int i,temp,list[N];
cout<<"ENTER ELEMENTS \n";
for( i=0 ; i<N ; i++ )
{
cin>>list[i];
}
for( i=0 ; i<N ; i=i+2 )
{
temp = list[i];
list[i] = list[i+1];
list[i+1]=temp;
}
cout<<"\nSHUFFLED ELEMENTS \n";
for( i=0 ; i<N ; i++ )
{
cout<<list[i]<<" ";
}
return 0;
}
OUTPUT