Advertisement
dmitryEfremov

Untitled

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