AdemDev

Локальные максимумы

Aug 31st, 2023 (edited)
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp
  4. {
  5. internal class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int[] array = new int[30];
  10.  
  11. int minValue = 0;
  12. int maxValue = 9;
  13. Random random = new Random();
  14.  
  15. Console.WriteLine("Сгенерированный массив:");
  16.  
  17. for (int i = 0; i < array.Length; i++)
  18. {
  19. array[i] = random.Next(minValue, maxValue + 1);
  20. Console.Write(array[i] + " ");
  21. }
  22.  
  23. Console.WriteLine("\nЛокальные максимумы:");
  24.  
  25. if (array[0] > array[1])
  26. Console.Write(array[0] + " ");
  27.  
  28. for (int i = 1; i < array.Length - 1; i++)
  29. if (array[i] > array[i - 1] && array[i] > array[i + 1])
  30. Console.Write(array[i] + " ");
  31.  
  32. if (array[array.Length - 1] > array[array.Length - 2])
  33. Console.Write(array[0] + " ");
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment