Explore
ProGrad Programs
Placement Prep
TCS Codevita
Live Placement Training
Webinars
About Us

Edit
Reply




Edit

Circular rotation of an array by K positions | Faceprep

Published on 06 Mar 2020

Circular array rotation means rotating the elements in the array where one rotation operation moves the last element of the array to the first position and shifts all remaining elements to the right.


For example, consider the following array = [4, 5, 6], number of rotations = 2, indexes to be checked = [0,1,2]

  • Initial array   [4, 5, 6]
  • After one rotation   [6, 4, 5]
  • After two rotations   [5, 6, 4]


OUTPUT


Element at index 0 : 5

Element at index 1 : 6

Element at index 2 : 4


C++
Java
Python 3

Output
Enter the number of elements of the array: 3
Enter the number of rotations of the array: 2
Enter the number of indexes to be displayed: 3

Input the array elements
1
2
3

The Array Elements are
1 2 3
Enter the index of the array to be displayed: 0
The element in the array is 2
Enter the index of the array to be displayed: 1
The element in the array is 3
Enter the index of the array to be displayed: 2
The element in the array is 1

If you have any feedback about this article and want to improve this, please write to enquiry@faceprep.in
Explore 'c plus plus'
Articles Practice Exercises