Advertisement
Guest User

4.7

a guest
Aug 17th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 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 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[] printArr)
  35. {
  36. for (int i = 0; i < printArr.Length; i++)
  37. {
  38. Console.Write(printArr[i] + " ");
  39. }
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement