W1thr

Функции-5

Feb 27th, 2021 (edited)
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Homework5
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  10.             Shuffle(numbers);
  11.         }
  12.  
  13.         static void Shuffle(int[] inputArray)
  14.         {
  15.             Random random = new Random();
  16.             for (int i = inputArray.Length-1; i >= 0; i--)
  17.             {
  18.                 int randomIndex = random.Next(0, i + 1);
  19.                 int tempValue = inputArray[i];
  20.                
  21.                 inputArray[i] = inputArray[randomIndex];
  22.                 inputArray[randomIndex] = tempValue;
  23.                 Console.Write(inputArray[i] + " ");
  24.             }
  25.         }
  26.     }
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment