Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Канзас_сити_шафл
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- int[] array = new int[10];
- int minNumber = 0;
- int maxNumber = 20;
- Random random = new Random();
- Console.WriteLine("Исходный массив: ");
- for (int i = 0; i < array.Length; i++)
- {
- array[i] = random.Next(minNumber, maxNumber);
- }
- DisplayArray(array);
- Console.WriteLine();
- Console.Write("Измененный массив: \n");
- Shuffle(array);
- DisplayArray(array);
- Console.WriteLine();
- }
- static void Shuffle(int[] array)
- {
- Random random = new Random();
- for (int i = array.Length - 1; i >= 1; i--)
- {
- int randomIndexInArray = random.Next(i + 1);
- int temporaryValue = array[randomIndexInArray];
- array[randomIndexInArray] = array[i];
- array[i] = temporaryValue;
- }
- }
- static void DisplayArray(int[] array)
- {
- for (int i = 0; i < array.Length; i++)
- {
- Console.Write(array[i] + " ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement