Advertisement
bonumopus

arraytask4_3

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