1// C program to rotate an array cyclically
2
3#include <stdio.h>
4
5void rightRotateByOne(int arr[], int n) //function for cyclically rotating an array once
6{
7 int x = arr[n-1], i;
8 for (i = n-1; i > 0; i--)
9 arr[i] = arr[i-1];
10 arr[0] = x;
11}
12
13int main()
14{int t;
15scanf("%d",&t);//number of test cases
16int p;
17for(p=0;p<t;p++){
18 int n,i,k;
19 scanf("%d %d",&n,&k); // n--> size of array ; k--> number of rotations
20 int arr[n];
21 k=k%n;
22 for(i=0;i<n;i++){
23 scanf("%d",&arr[i]);
24 }
25int j;
26 for(j=0;j<k;j++) //cyclically rotating an array k times
27{rightRotateByOne(arr, n);}
28
29
30 for (i = 0; i < n; i++){
31 printf("%d ", arr[i]);}
32 printf("\n");}
33
34 return 0;
35}
36