Created
May 17, 2024 08:31
-
-
Save FleamRus/7ac6b78601940b2bb5e431b64be0aeef 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; | |
namespace Канзас_сити_шафл | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
int[] array = { 1, 2, 3, 4, 5 }; | |
Console.WriteLine("Изначальный массив : "); | |
for (int i = 0; i < array.Length; i++) | |
{ | |
Console.Write(array[i]); | |
} | |
Console.WriteLine("\nПеретасованный массив: \n "); | |
Shuffle(array); | |
} | |
static void Shuffle(int[] array) | |
{ | |
Random random = new Random(); | |
for (int i = array.Length - 1; i >= 0; i--) | |
{ | |
int j = random.Next(i + 1); | |
int temp = array[j]; | |
array[j] = array[i]; | |
array[i] = temp; | |
Console.Write(temp); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment