Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace homeWorkShiftingArrayValues
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Random random = new Random();
- int maxSizeArray = 10;
- int maxValue = 9;
- int minValue = 0;
- int tempValue = 0;
- int stepShift;
- int startIndex = 0;
- int[] numbers = new int[maxSizeArray];
- for (int i = 0; i < numbers.Length; i++)
- {
- numbers[i] = random.Next(minValue, maxValue + 1);
- }
- Console.Write("Исходный массив: ");
- foreach (int number in numbers)
- {
- Console.Write(number + " ");
- }
- Console.WriteLine();
- Console.Write("Введите число на которое хотите сдвинуть массив: ");
- stepShift = Convert.ToInt32(Console.ReadLine());
- stepShift = stepShift % numbers.Length;
- for (int i = 0; i < stepShift; i++)
- {
- tempValue = numbers[startIndex];
- for (int j = 0; j < tempValue - 1; j++)
- {
- numbers[j] = numbers[j + 1];
- }
- numbers[numbers.Length - 1] = tempValue;
- }
- Console.WriteLine();
- Console.Write($"Массив свдинутый на {stepShift}: ");
- foreach ( var number in numbers)
- {
- Console.Write(number + " ");
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement