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 

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz