holllowknight

ДЗ: Максимум

Mar 12th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 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 Maximus
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] array = new int[30] { 1, 9, 2, 8, 3, 7, 4, 6, 6, 0,
  14.                 1, 23, 56, 78, 54, 32, 83, 10, 20, 999,
  15.                 92, 19, 33, 48, 59, 28, 43, 15, 12, 12 };
  16.  
  17.             Console.Write("Локальные максимумы: ");
  18.             if (array[0] >= array[1]) Console.Write("{0} ", array[0]);
  19.  
  20.             for (int i = 0; i < array.Length - 2; i++)
  21.             {
  22.                 if ((array[i + 1] >= array[i]) && (array[i + 1] >= (array[i + 2]))) Console.Write("{0} ", array[i + 1]);
  23.             }
  24.  
  25.             if (array[array.Length - 1] >= array[array.Length - 2]) Console.Write("{0} ", array[array.Length - 1]);
  26.         }
  27.     }
  28. }
Add Comment
Please, Sign In to add comment