• + 7 comments

    This is my C# sharp code.

            string[] s1 = Console.ReadLine().Split(' ');
            int n = int.Parse(s1[0]);
            int k = int.Parse(s1[1]);
    
            string[] s = Console.ReadLine().Split(' ');
            int[] array = new int[n];
    
            ////pre-rotation of array method:
            //-----------------------------------Right rotation
            //for (int i = 0; i < n; i++)
            //{
            //    array[(i + k) % n] = int.Parse(s[i]);
            //}
    
            //------------------------------------Left rotation
            for (int i = 0; i < n; i++)
            {
                array[(i + (n-k)) % n] = int.Parse(s[i]);
            }
    
            for (int i = 0; i < n; i++)
            {
                Console.WriteLine(array[i]+" ");
            }