SHARE
TWEET

4.7

a guest Aug 17th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp5
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] massiv = new int[5] { 1, 2, 3, 4, 5 };
  14.             Console.WriteLine("Исходный массив");
  15.             PrintArray(massiv);
  16.             Console.WriteLine("\nПеремешанный массив");
  17.             PrintArray(Shuffle(massiv));
  18.             Console.WriteLine();
  19.         }
  20.  
  21.         static int[] Shuffle(int[] arr)
  22.         {
  23.             Random rand = new Random();
  24.             for (int i = 0; i < arr.Length; i++)
  25.             {
  26.                 int n = rand.Next(arr.Length);
  27.                 int m = arr[i];
  28.                 arr[i] = arr[n];
  29.                 arr[n] = m;
  30.             }
  31.             return arr;
  32.         }
  33.  
  34.         static void PrintArray(int[] massiv)
  35.         {
  36.             for (int i = 0; i < massiv.Length; i++)
  37.             {
  38.                 Console.Write(massiv[i] + " ");
  39.             }
  40.         }
  41.     }
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top