Advertisement
dmitryEfremov

Untitled

May 17th, 2020
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp11
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. Console.Write("Введите объём массива - ");
  10. int volume = Convert.ToInt32(Console.ReadLine());
  11. int[] array = new int[volume];
  12. Console.WriteLine("Заполните массив:");
  13. FillingArray(array);
  14. Shuffle(array);
  15. Console.WriteLine("Ваш массив перемешан:");
  16. DrawArray(array);
  17. }
  18.  
  19. static void Shuffle(int[] array)
  20. {
  21. Random rnd = new Random();
  22. for (int i = 0; i < rnd.Next(); i++)
  23. {
  24. (int index1, int index2) replacement = (default, default);
  25. replacement.index1 = rnd.Next(0, array.Length - 1);
  26. replacement.index2 = rnd.Next(0, array.Length - 1);
  27. int tempElement = array[replacement.index1];
  28. array[replacement.index1] = array[replacement.index2] ;
  29. array[replacement.index2] = tempElement
  30. }
  31. }
  32.  
  33. static void FillingArray(int [] array)
  34. {
  35. for (int i = 0; i < array.Length; i++)
  36. {
  37. Console.Write($"{i + 1} - ");
  38. array[i] = Convert.ToInt32(Console.ReadLine());
  39. }
  40. Console.Clear();
  41. }
  42.  
  43. static void DrawArray(int [] array)
  44. {
  45. for (int i = 0; i < array.Length; i++)
  46. Console.Write(array[i] + " ");
  47. Console.ReadLine();
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement