n rotations the left and right of array
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,i,r;
cout<<"enter the size of array : ";
cin>>n;
int a[n];
for(i=0;i<n;i++)
cin>>a[i];
cout<<"enter the no. of rotations : ";
cin>>r;
r=r%n;
cout<<"For the left rotations\n";
for(i=r;i<n;i++)
cout<<a[i]<<" ";
for(i=0;i<r;i++)
cout<<a[i]<<" ";
cout<<"\nFor the right rotations\n";
for(i=n-r;i<n;i++)
cout<<a[i]<<" ";
for(i=0;i<n-r;i++)
cout<<a[i]<<" ";
}
Comments
Post a Comment