Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace shift_of_numbers_in_array
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Random random = new Random();
- int numberOfShift;
- int minRandomValue = 1;
- int maxRandomValue = 10;
- int lenghtArray = 30;
- int[] numbers = new int[lenghtArray];
- Console.WriteLine("Массив:");
- for (int i = 0; i < numbers.Length; i++)
- {
- numbers[i] = random.Next(minRandomValue, maxRandomValue);
- Console.Write(numbers[i] + " ");
- }
- Console.Write("\n\nВведите на сколько сдвинуть массив:");
- numberOfShift = Convert.ToInt32(Console.ReadLine());
- if(numberOfShift > lenghtArray)
- {
- numberOfShift = numberOfShift%lenghtArray;
- }
- for (int i = 0; i < numberOfShift; i++)
- {
- int tempNumber = numbers[0];
- for (int j = 1; j < numbers.Length; j++)
- {
- numbers[j - 1] = numbers[j];
- }
- numbers[numbers.Length - 1] = tempNumber;
- }
- Console.WriteLine($"\n\nМассив со сдвинутыми числами на {numberOfShift} влево:");
- for (int i = 0; i < numbers.Length; i++)
- {
- Console.Write(numbers[i] + " ");
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement