Advertisement
Guest User

3.5

a guest
Nov 15th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 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 _3._5
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int size = 30;
  14.             int[] array = new int[size];
  15.  
  16.             Random random = new Random();
  17.             Console.WriteLine("Есть ряд чисел из 30 элементов: ");
  18.  
  19.             for (int i = 0; i < array.Length; i++)
  20.             {
  21.                 array[i] = random.Next(10, 100);
  22.                 Console.Write(array[i] + " ");
  23.             }
  24.            
  25.             Console.WriteLine();
  26.             Console.WriteLine("Из них локальные максимумы будут: ");
  27.  
  28.             for (int i = 0; i < array.Length; i++)
  29.             {
  30.                 if (i == 0)
  31.                 {
  32.                     if (array[i] > array[i + 1])
  33.                     {
  34.                         Console.Write(array[i] + " ");
  35.                     }
  36.                 }
  37.                
  38.                 else if (i == array.Length - 1)
  39.                 {
  40.                     if (array[i] > array[i - 1])
  41.                     {
  42.                         Console.Write(array[i] + " ");
  43.                     }
  44.                 }
  45.                
  46.                 else if (array[i] > array[i - 1] && array[i] > array[i + 1])
  47.                 {
  48.                     Console.Write(array[i] + " ");
  49.                 }
  50.             }
  51.                 Console.WriteLine();
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement