Advertisement
illiden

LocalMax v.3

Dec 1st, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 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 LocalMax
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] array = new int[30];
  14.             Random rand = new Random();
  15.  
  16.             Console.WriteLine("Числа: ");
  17.             for (int i = 0; i < array.Length; i++)
  18.             {
  19.                 Console.Write("\n" + (i + 1) + ". ");
  20.                 array[i] = rand.Next(0, 100);
  21.                 Console.Write(array[i]);
  22.             }
  23.  
  24.             Console.WriteLine("\n\nЛокальные максимумы: ");
  25.             if (array[0] > array[1])
  26.             {
  27.                 Console.WriteLine("1. " + array[0]);
  28.             }
  29.             for (int i = 1; i < array.Length - 1; i++)
  30.             {
  31.                     if (array[i] > array[i - 1] && array[i] > array[i + 1])
  32.                     {
  33.                         Console.WriteLine((i + 1) + ". " + array[i]);
  34.                     }
  35.             }
  36.             if (array[array.Length - 1] > array[array.Length - 2])
  37.             {
  38.                 Console.WriteLine(array.Length + ". " + array[array.Length - 1]);
  39.             }
  40.             Console.ReadKey();
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement