Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp9
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.CursorVisible = false;
  14.             bool isOpen = true;
  15.             int[] array = new int[10];
  16.  
  17.             Console.WriteLine("Чтобы перемешать массив нажмите 5");
  18.             Console.WriteLine("Чтобы выйти нажмите любую другую кнопку");
  19.             CompletionArray(array);
  20.             while (isOpen)
  21.             {
  22.                 if (Console.ReadLine() == "5")
  23.                 {
  24.                     array = Shuffle(array);
  25.                 }
  26.                 else
  27.                 {
  28.                     isOpen = false;
  29.                 }
  30.                 Console.WriteLine();
  31.             }
  32.         }
  33.  
  34.         static void CompletionArray (int[] array)
  35.         {
  36.             Random rand = new Random();
  37.             for (int i = 0; i < array.Length; i++)
  38.             {
  39.                 array[i] = rand.Next(10, 99);
  40.                 Console.Write(array[i] + " ");
  41.             }
  42.             Console.WriteLine();
  43.         }
  44.         static int[] Shuffle (int [] array)
  45.         {
  46.             Random rand = new Random();
  47.             for (int i = array.Length - 1; i >= 0; i--)
  48.             {
  49.                 int j = rand.Next(i + 1);
  50.                 int n = array[j];
  51.                 array[j] = array[i];
  52.                 array[i] = n;
  53.                 Console.Write(array[i] + " ");
  54.             }
  55.             return array;
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement