Created
May 8, 2024 02:09
-
-
Save FleamRus/d3555cb3ac2f06b49f4cdd16e91c00b6 to your computer and use it in GitHub Desktop.
Сдвиг значений массива
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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