Last active
May 7, 2025 15:56
-
-
Save Strelok78/103e8980143857fd3f1e9470aa4b7e5c to your computer and use it in GitHub Desktop.
Shift values in array to left on value entered by user
This file contains hidden or 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
namespace iJuniorPractice | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; | |
int shiftLeftValue; | |
int shiftsCount; | |
Console.WriteLine("Original array:"); | |
foreach (var number in numbers) | |
{ | |
Console.Write(number + " "); | |
} | |
Console.WriteLine(); | |
Console.Write("Enter the value you want the numbers to be shifted left: "); | |
shiftLeftValue = int.Parse(Console.ReadLine()); | |
shiftsCount = shiftLeftValue % numbers.Length; | |
for (int i = 0; i < shiftsCount; i++) | |
{ | |
int temporary = numbers[0]; | |
for (int j = 0; j < numbers.Length - 1; j++) | |
{ | |
numbers[j] = numbers[j + 1]; | |
} | |
numbers[numbers.Length - 1] = temporary; | |
} | |
Console.WriteLine("Shifted array: "); | |
foreach (var number in numbers) | |
{ | |
Console.Write(number + " "); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment