Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Random random = new Random();
- int arrayLength = 30;
- int minimumNumberInArray = 1;
- int maximumNumberInArray = 9;
- int[] array = new int[arrayLength];
- int inputCountForMoveLeft;
- int countForMoveLeft;
- int tempFirstNumber;
- Console.WriteLine($"Одномерный массив с длиной {arrayLength}:");
- for (int i = 0; i < array.Length; i++)
- {
- array[i] = random.Next(minimumNumberInArray, maximumNumberInArray + 1);
- Console.Write(array[i] + " ");
- }
- Console.WriteLine();
- Console.Write("На сколько элементов сдвинуть массив влево? ");
- inputCountForMoveLeft = Convert.ToInt32( Console.ReadLine() );
- countForMoveLeft = inputCountForMoveLeft % array.Length;
- for (int i = 0; i < countForMoveLeft; i++)
- {
- tempFirstNumber = array[0];
- for(int j = 1; j < array.Length; j++)
- {
- array[j - 1] = array[j];
- }
- array[array.Length - 1] = tempFirstNumber;
- }
- Console.WriteLine($"Массив сдвинутый на {inputCountForMoveLeft} влево:");
- for (int i = 0; i < array.Length; i++)
- {
- Console.Write(array[i] + " ");
- }
- Console.WriteLine();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement