Skip to content

Instantly share code, notes, and snippets.

@Strelok78
Last active May 17, 2023 12:05
Show Gist options
  • Save Strelok78/983eb104ffe3ebf6ccf6f0baa4e99a9e to your computer and use it in GitHub Desktop.
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.
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