Advertisement
dmitryEfremov

Untitled

May 17th, 2020
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 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 = rnd.Next(0, array.Length - 1);
  25. int index2 = rnd.Next(0, array.Length - 1);
  26. int num = array[index1];
  27. array[index1] = array[index2] ;
  28. array[index2] = num;
  29. }
  30. }
  31.  
  32. static void FillingArray(int [] array)
  33. {
  34. for (int i = 0; i < array.Length; i++)
  35. {
  36. Console.Write($"{i + 1} - ");
  37. array[i] = Convert.ToInt32(Console.ReadLine());
  38. }
  39. Console.Clear();
  40. }
  41.  
  42. static void DrawArray(int [] array)
  43. {
  44. for (int i = 0; i < array.Length; i++)
  45. Console.Write(array[i] + " ");
  46. Console.ReadLine();
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement