Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save FleamRus/d3555cb3ac2f06b49f4cdd16e91c00b6 to your computer and use it in GitHub Desktop.
Save FleamRus/d3555cb3ac2f06b49f4cdd16e91c00b6 to your computer and use it in GitHub Desktop.
Сдвиг значений массива
using System;
namespace Сдвиг_значений_массива
{
internal class Program
{
static void Main(string[] args)
{
int[] numbers = { 1, 2, 3, 4, 5 };
int countOfCycles;
int userInput;
Console.WriteLine("Исходный массив: \n");
foreach (int number in numbers)
{
Console.Write(number);
}
Console.Write("\n\nВведите количество сдвигов: \n\n");
userInput = Convert.ToInt32(Console.ReadLine());
countOfCycles = userInput % numbers.Length;
for (int i = 0; i < countOfCycles; 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.WriteLine("\n\nСдвинутый массив: \n");
foreach (int number in numbers)
{
Console.Write(number);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment