C# program to right rotate an array

C# Program to perform right circular rotation of an array.
Hi Guy’s. here is the program to perform right circular rotation of array elements using c# program. we can move array elements using c# codes.

output :

Code Explanation :
step 1 : if you debug/run the program then control goes to Main method thereafter that go inside of the Main.
step 2 : i have taken 1 integer array variables a. initialize numbers with 8,6,4,21. int[] a = new int[] {8,6,4,21};
step 3 : next control move to move method and compiler send control to move method block.move(a);
step 4 : now arr receive all values of a and now control move to move method.static void move(int[] arr).
step 5 : there i have taken two integer variable size,temp. int size = arr.Length = 4;

step 6 : now control move to for method. for(int j = 0; j < size – 1; j++) j = 4-1=3. 3>0 true.
step 7 : temp = arr[0]; arr[0]=8; temp = 8;
step 8 : arr[0] = arr[j+1];arr[j+1]=arr[0+1]=arr[1]; arr[0]=arr[1]=6;arr[0]=6;
step 9 : arr[j+1] = temp;arr[1]=temp;arr[1]=8; and loop continue until continue false.
step 10 : after doing right rotation arr values go to nnum. foreach (int num in arr)
step 11 : it prints all n values.Console.Write(num + ” “);
step 12 : next control terminate move method and control back to move(a); method.
step 13 : Console.ReadLine(); it takes a input from keyboard and terminate

Happy Coding… Thanks.

Post Author: adama