Skip to content

Commit

Permalink
Arrays
Browse files Browse the repository at this point in the history
To cyclically rotate an array by one.
  • Loading branch information
dhruviagrawal committed Mar 14, 2021
1 parent 1af54d9 commit ee813d9
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions CyclicRotationArray.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <bits/stdc++.h>
using namespace std;

void rotate(int a[], int n)
{
int i,temp=a[n-1];
for(int i=n-1;i>=0;i--)
{
a[i]=a[i-1];
}
a[0]=temp;
}

int main()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
rotate(a,n);
for(int i=0;i<n;i++)
cout<<a[i]<<" ";
return 0;
}

0 comments on commit ee813d9

Please sign in to comment.