Last active
March 27, 2024 15:16
-
-
Save kyzalex/e0a02eb4ac8f10caa0641454df624b0c 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
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
int[] array = new int[10]; | |
for (int i = 0; i < array.Length; i++) | |
{ | |
array[i] = i; | |
} | |
PrintArray(array); | |
Shuffle(array); | |
Console.WriteLine(); | |
PrintArray(array); | |
Console.ReadKey(); | |
} | |
static void PrintArray(int[] array) | |
{ | |
for (int i = 0; i < array.Length; i++) | |
{ | |
Console.Write(array[i] + " "); | |
} | |
} | |
static void Shuffle(int[] array) | |
{ | |
Random random = new Random(); | |
int temp; | |
for (int i = 0; i < array.Length; i++) | |
{ | |
int randomIndex = random.Next(array.Length); | |
temp = array[i]; | |
array[i] = array[randomIndex]; | |
array[randomIndex] = temp; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment