Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- internal class Program
- {
- static void Main(string[] args)
- {
- int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
- int numberShifts;
- string userInput;
- Console.Write("Массив: ");
- foreach (int number in numbers)
- {
- Console.Write(number + " ");
- }
- Console.Write("\nНа сколько сдвинуть массив влево: ");
- userInput = Console.ReadLine();
- if (int.TryParse(userInput, out int num))
- {
- numberShifts = num % numbers.Length;
- for (int i = 0; i < numberShifts; i++)
- {
- int tempNumber = numbers[0];
- for (int j = 0; j < numbers.Length - 1; j++)
- {
- numbers[j] = numbers[j + 1];
- }
- numbers[numbers.Length - 1] = tempNumber;
- }
- Console.Write("Сдвинутый массив: ");
- foreach(int number in numbers)
- {
- Console.Write(number + " ");
- }
- }
- else
- {
- Console.WriteLine("Ошибка ввода.");
- }
- Console.ReadKey();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement