Skip to content

Instantly share code, notes, and snippets.

@NoDamage111
Created April 24, 2024 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NoDamage111/c36a44ad4749f9a89dcb26d479e25bcb to your computer and use it in GitHub Desktop.
Save NoDamage111/c36a44ad4749f9a89dcb26d479e25bcb to your computer and use it in GitHub Desktop.
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