-
-
Save StrikerXx798/3209658acc1d63c197e3b54992a39773 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
using System; | |
using System.Text; | |
namespace ConsoleApp1 | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.InputEncoding = Encoding.Unicode; | |
Console.OutputEncoding = Encoding.Unicode; | |
int[] ints = new int[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; | |
DrawArray(ints, "До перемешивания:"); | |
ShuffleArray(ints); | |
DrawArray(ints, "После перемешивания:"); | |
} | |
static void ShuffleArray(int[] array) | |
{ | |
Random random = new Random(); | |
int arrayLength = array.Length; | |
for (int i = arrayLength - 1; i >= 0; i--) | |
{ | |
int randomIndex = random.Next(0, arrayLength); | |
int temp = array[i]; | |
array[i] = array[randomIndex]; | |
array[randomIndex] = temp; | |
} | |
} | |
static void DrawArray(int[] array, string text) | |
{ | |
Console.WriteLine(text); | |
foreach (int i in array) | |
{ | |
Console.Write(i + " "); | |
} | |
Console.WriteLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment