Answer to Question #155968 in C++ for Abdul Rehman

Question #155968

Write a C++ program in which, read data from user into an integer array and an integer n. now rotate the array n times. 



1
Expert's answer
2021-01-18T15:02:23-0500


#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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS