Thursday 27 September 2018

Array Rotation Implementation in C++ and C

#include<bits/stdc++.h>
using namespace std;

void rotate(int a[],int n)
{
int j;
for(int i=0;i<6;i++)
{
int b=a[0];
for(j=0;j<6;j++)
{
a[j]=a[j+1];
}
a[j]=b;
}


}

int main()
{
int arr[]={1,2,3,4,5,6},n=2;
rotate(arr,n);
// n== rotate by
for(int i=0;i<6;i++)
cout<<arr[i]<<" ";

}

No comments:

Post a Comment

Amazon1Ads