Programming Examples
Cpp program to rotate shift the array one position to the right.
Write a Cpp program to rotate the array one position to the right.
Solution
#include<iostream>
using namespace std;
int main(){
int num[5],a,temp;
cout<<"Enter 5 positive integer numbers"<<endl;
for(a=0;a<5;a++)
{
cin>>num[a];
}
temp=num[5];
for(a=5;a>=1;a--)
{
num[a]=num[a-1];
}
num[0]=temp;
for(a=0;a<5;a++)
{
cout<<num[a]<<" ";
}
return 0;
}
Output
Enter 5 positive integer numbers
1
2
3
4
5
5 1 2 3 4Â