Advertisement
pol9na

Untitled

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