Advertisement
RedFlys

Home Work 3.5

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