Advertisement
TargeTPoweR

Local Maxis

Mar 23rd, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 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 Tasks
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int[] array = { 45,30, 4, 8, 15, 5, 3, 7, 9, 4, 5, 6, 7, 4, 17, 3, 5, 7, 8, 4, 3, 2, 13, 6, 6, 4, 2,7,3,21 };
  14. int localMax;
  15. Console.WriteLine("Локальные максимумы в данном массиве: ");
  16.  
  17. if (array[0] > array[1])
  18. {
  19. localMax = array[0];
  20. Console.WriteLine(localMax);
  21. }
  22.  
  23. for (int i = 1; i < array.Length -1; i++ )
  24. {
  25. if (array[i-1] < array[i] && array[i] > array[i+1] )
  26. {
  27. localMax = array[i];
  28. Console.WriteLine(localMax);
  29. }
  30. }
  31. if (array[array.Length -1] > array[array.Length -2])
  32. {
  33. localMax = array[array.Length - 1];
  34. Console.WriteLine(localMax);
  35. }
  36. Console.WriteLine("Длинна массива" + " " + array.Length + " элементов.");
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement