Last active
February 9, 2025 11:55
-
-
Save areaartez51/759d9581fc3cedc1b831e4a0e6e1b2ad to your computer and use it in GitHub Desktop.
Shifting array values
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 ShiftingArrayValues | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
const int QuantityRowMatrix = 10; | |
int[] numbers = new int[QuantityRowMatrix]; | |
Random random = new Random(); | |
int minimumRangeRandom = 1; | |
int maximumRangeRandom = 10; | |
int userInput; | |
int bufferValue; | |
for (int i = 0; i < numbers.Length; i++) | |
{ | |
numbers[i] = random.Next(minimumRangeRandom, maximumRangeRandom); | |
Console.Write(numbers[i] + ", "); | |
} | |
Console.WriteLine("\nНа сколько сдвинуть знаения в массиве?"); | |
userInput = Convert.ToInt32(Console.ReadLine()) % numbers.Length; | |
for (int j = 0; j < userInput; j++) | |
{ | |
for (int i = 0; i < numbers.Length - 1; i++) | |
{ | |
bufferValue = numbers[i]; | |
numbers[i] = numbers[i + 1]; | |
numbers[i + 1] = bufferValue; | |
} | |
} | |
for (int i = 0; i < numbers.Length; i++) | |
{ | |
Console.Write(numbers[i] + ", "); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment