Advertisement
NelIfandieva

ExArrays_04_ArrayRotation

Jan 30th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.63 KB | None | 0 0
  1. int[] array = Console.ReadLine()
  2.                 .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  3.                 .Select(int.Parse)
  4.                 .ToArray();
  5.  
  6.             int numOfRotations = int.Parse(Console.ReadLine());
  7.  
  8.             for (int rotation = 1; rotation <= numOfRotations; rotation++)
  9.             {
  10.                 int first = array[0];
  11.  
  12.                 for (int i = 0; i < array.Length - 1; i++)
  13.                 {
  14.                     array[i] = array[i + 1];
  15.                 }
  16.  
  17.                 array[array.Length - 1] = first;
  18.             }
  19.  
  20.             Console.Write(string.Join(" ", array));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement