Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp19
- {
- class Program
- {
- public static void LocalMax(int[] c)
- {
- if (c.Length <= 1)
- {
- Console.WriteLine(c[0] + " ");
- return;
- }
- if (c.Length == 2 && c[0] > c[1])
- {
- Console.WriteLine(c[0] + " ");
- return;
- }
- else if (c.Length == 2 && c[0] < c[1])
- {
- Console.WriteLine(c[1] + " ");
- return;
- }
- if (c[0] > c[1])
- {
- Console.WriteLine(c[0] + " ");
- }
- //10, 5, 9, 4, 6
- for (int i = 1; i < c.Length-1; i++)
- {
- if (c[i] > c[i + 1] && c[i] > c[i - 1])
- {
- Console.WriteLine(c[i] + " ");
- }
- }
- if (c[c.Length - 1] > c[c.Length - 2])
- {
- Console.WriteLine(c[c.Length - 1] + " ");
- }
- return;
- }
- static void Main(string[] args)
- {
- int[] nums = { 10, 5, 9, 4, 6, 11, 4, 60, 34 , 35 };
- Console.WriteLine(LocalMax(nums));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement