Advertisement
magrega

Untitled

Jun 7th, 2021
118
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 ConsoleApp19
  4. {
  5. class Program
  6. {
  7.  
  8. public static void LocalMax(int[] c)
  9. {
  10. if (c.Length <= 1)
  11. {
  12. Console.WriteLine(c[0] + " ");
  13. return;
  14. }
  15.  
  16. if (c.Length == 2 && c[0] > c[1])
  17. {
  18. Console.WriteLine(c[0] + " ");
  19. return;
  20. }
  21.  
  22. else if (c.Length == 2 && c[0] < c[1])
  23. {
  24. Console.WriteLine(c[1] + " ");
  25. return;
  26. }
  27.  
  28. if (c[0] > c[1])
  29. {
  30. Console.WriteLine(c[0] + " ");
  31.  
  32. }
  33.  
  34. //10, 5, 9, 4, 6
  35.  
  36. for (int i = 1; i < c.Length-1; i++)
  37. {
  38.  
  39. if (c[i] > c[i + 1] && c[i] > c[i - 1])
  40. {
  41. Console.WriteLine(c[i] + " ");
  42.  
  43. }
  44.  
  45.  
  46. }
  47.  
  48. if (c[c.Length - 1] > c[c.Length - 2])
  49. {
  50. Console.WriteLine(c[c.Length - 1] + " ");
  51.  
  52. }
  53.  
  54. return;
  55.  
  56. }
  57.  
  58.  
  59. static void Main(string[] args)
  60. {
  61. int[] nums = { 10, 5, 9, 4, 6, 11, 4, 60, 34 , 35 };
  62. Console.WriteLine(LocalMax(nums));
  63. }
  64. }
  65. }
  66.  
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement