This Example domonstarte the use of c++ mod  operator ( %)  in order to rotate an array with number of integer (positive and negative )

Algorithm
This program uses 6 element array
The algorithm is the rotated element in the rotated array is    b[i] = a[((  (i+k)  %6)+6)%6];
where b[i]  is the rotated element  and a [i] is the original element

 

 

 

 

 

 

 

#include <iostream>
using namespace std ;



int main (){
cout<<" This program alllow to rotate an arary of integers in both directions positive and negative ";

int a[6] ={1,2,3,4,5,6}; //original array
int k ; // Number of shifts in the rotation
int b[6] ; // the rotated array wheere 6 is the length of the array
cout<<"\n Enter the number of digits ( both positive and negative) ";
//c++ mod operator
cin>>k ;
cout<<endl<<"the nuunmber of rotation " << k<<endl;
for (int i=0; i<6;++i){
b[i] = a[(((i+k)%6)+6)%6];// // if K<-6 then we have (i+k) is negative ,after that (i+k) % 6 is > -6
cout<< "a["<<i+1 <<"] = "<<a[i]<<" ,b[" <<i+1 <<"] = "<< b[i] <<endl ;
}
return 0 ;

}