Last active
September 28, 2025 17:02
-
-
Save Attosius/8a47db9409444d402b548f7ac17c3a44 to your computer and use it in GitHub Desktop.
ДЗ: Канзас сити шафл
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
| using System; | |
| namespace IJuniorTasks | |
| { | |
| internal class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| var arrayToSort = new[] {1, 2, 3, 4, 5}; | |
| WriteArray(arrayToSort); | |
| Shuffle(arrayToSort); | |
| Console.WriteLine(); | |
| WriteArray(arrayToSort); | |
| Console.ReadKey(); | |
| } | |
| public static void Shuffle(int[] array) | |
| { | |
| var random = new Random(); | |
| for (int i = 0; i < array.Length; i++) | |
| { | |
| var indexToChange = random.Next(array.Length); | |
| var temp = array[i]; | |
| array[i] = array[indexToChange]; | |
| array[indexToChange] = temp; | |
| } | |
| } | |
| public static void WriteArray(int[] 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