Write a C++ program in which, read data from user into an integer array and an integer n. now rotate the array n times.
#include<iostream>
using namespace std;
int main(){
int a[10];
for(int p=0;p<=10;p++){
cout<<"enter number"<<p<<endl;
cin>>a[p];
}
int temp[10];
int r;
cout<<"Number of rotation"<<endl;
cin>>r;
for(int i=9;i>=0;i--)
{
if(i+r>=10)
{
temp[i+r-10]=a[i];
}
else
{
temp[i+r]=a[i];
}
}
for( i=1;i<10;i++)
{
cout<<temp[i]<<"\t";
}
return 0
Comments
Leave a comment