Last active
May 17, 2023 12:05
-
-
Save Strelok78/983eb104ffe3ebf6ccf6f0baa4e99a9e to your computer and use it in GitHub Desktop.
Shifts the number by the user-specified position value to the left using loops, without using other arrays.
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 iJuniorRefactoring | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
int[] numbers = { 1, 2, 3, 4, 5 }; | |
int temp; | |
ShowArray(numbers); | |
Console.WriteLine("\n\nHow many steps to shift the numbers in the array?"); | |
int.TryParse(Console.ReadLine(), out int step); | |
step %= numbers.Length; | |
for (int i = 0; i < step; i++) | |
{ | |
temp = numbers[0]; | |
for (int j = 0; j < numbers.Length - 1; j++) | |
{ | |
numbers[j] = numbers[j + 1]; | |
} | |
numbers[numbers.Length - 1] = temp; | |
} | |
ShowArray(numbers); | |
} | |
private static void ShowArray(int[] array) | |
{ | |
Console.Write("Array: "); | |
for (int i = 0; i < array.Length; i++) | |
{ | |
Console.Write(array[i] + " "); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment