Created
April 24, 2024 17:47
-
-
Save NoDamage111/c36a44ad4749f9a89dcb26d479e25bcb 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 ConsoleApp18 | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Random random = new Random(); | |
int minValue = 0; | |
int maxValue = 100; | |
int[] massive = new int[50]; | |
for (int i = 0; i < massive.Length; i++) | |
{ | |
massive[i] = random.Next(minValue, maxValue + 1); | |
} | |
Console.WriteLine("Начальный массив: "); | |
WriteMassive(massive); | |
Shuffle(massive); | |
Console.WriteLine("\nПеремешанный массив: "); | |
WriteMassive(massive); | |
Console.ReadKey(); | |
} | |
static int[] Shuffle(int[] massive) | |
{ | |
Random random = new Random(); | |
int minValue = 0; | |
int maxValue = 1; | |
int temp; | |
for (int i = 0; i < massive.Length; i++) | |
{ | |
for (int j = 0; j < massive.Length - 1; j++) | |
{ | |
if (random.Next(minValue, maxValue+1)>0) | |
{ | |
temp = massive[j + 1]; | |
massive[j + 1] = massive[j]; | |
massive[j] = temp; | |
} | |
} | |
} | |
return massive; | |
} | |
static void WriteMassive(int[] massive) | |
{ | |
for (int i = 0; i < massive.Length; i++) | |
{ | |
Console.Write($"{massive[i]} "); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment