1 // Shift array elements to right
2 const int SIZE = 9;
3 int arr[SIZE]={1,2,3,4,5,6,7,8,9};
4
5 int last = arr[SIZE - 1];
6 for (int i = SIZE - 1; i > 0; i--)
7 arr[i] = arr[i - 1];
8
9 arr[0] = last;
1# include <iostream>
2using namespace std;
3
4void rotate(int arr[], int n)
5{
6 int last = arr[n - 1], i;
7 for (i = n - 1; i > 0; i--)
8 arr[i] = arr[i - 1];
9 arr[0] = last;
10}
11
12
13int main()
14{
15 int arr[100], i;
16 int n, turns;
17
18 cin >> n;
19
20 for(i=0;i<n;i++){
21 scanf("%d", &arr[i]);
22 }
23
24 cin >> turns;
25
26 while(turns>=1){
27 rotate(arr,n);
28 turns--;
29 }
30
31 for(i=0;i<n;i++){
32 cout << arr[i] << " ";
33 }
34
35 return 0;
36}
37
38
1 int temp=arr[0];
2 /******************************** Method 1
3 for (int i = 0; i < SIZE - 1; i++)
4 {
5 arr[i] = arr[i + 1];
6 }
7 arr[SIZE-1]=temp;
8 */
9 // Method 2
10 for (int i = 1; i < SIZE - 1; i++)
11 {
12 arr[i - 1] = arr[i];
13 }
14 arr[SIZE - 1] = temp;
15 for (int i = 0; i < SIZE; i++)
16 cout << arr[i] << "\t";
17 cout << endl;
18