Forked from QRemark/gist:143812e230d413b57a19891251f3f147
Created
January 21, 2024 06:58
-
-
Save DawallAZllon91/6f8034743074f5e7356a7abca5c8b110 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; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Сдвиг_значений_массива | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Random random = new Random(); | |
int randomNumberMax = 101; | |
int randomNumberMin = 0; | |
int arraySize; | |
int shift; | |
int tempElement; | |
Console.Write("Здравствуйте! Введите размерность массива в виде числа: "); | |
arraySize = Convert.ToInt32(Console.ReadLine()); | |
int[] array = new int[arraySize]; | |
Console.WriteLine("Результат генерации одномерного массива размера " + | |
$"{arraySize}: "); | |
for (int i = 0; i < arraySize; i++) | |
{ | |
array[i] = random.Next(randomNumberMin, randomNumberMax); | |
Console.Write(array[i] + " "); | |
} | |
Console.WriteLine("\nВведите значение, на сколько нужно сдвинуть массив влево, " + | |
"цифрой: "); | |
shift = Convert.ToInt32(Console.ReadLine()) % arraySize; | |
Console.WriteLine($"Эффективное число сдвига равно: {shift}."); | |
for (int i = 0; i < shift; i++) | |
{ | |
tempElement = array[0]; | |
for (int j = 0; j < array.Length - 1; j++) | |
{ | |
array[j] = array[j + 1]; | |
} | |
array[array.Length-1] = tempElement; | |
} | |
Console.WriteLine("Результат операции: "); | |
foreach (int shiftNumbers in array) | |
{ | |
Console.Write(shiftNumbers + " "); | |
} | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gistfile1.txt