Advertisement
GPbl3YH

CSLight #17

Jan 24th, 2021
713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 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 CSLight
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int arraySize;
  14.  
  15.             Console.WriteLine("Введите размер массива: ");
  16.             arraySize = Convert.ToInt32(Console.ReadLine());
  17.  
  18.  
  19.             int[] array = new int[arraySize];
  20.             Random rand = new Random();
  21.  
  22.  
  23.             for (int x = 0; x < arraySize; x++)
  24.             {
  25.                 array[x] = rand.Next(0, 100);
  26.             }
  27.  
  28.  
  29.             Console.WriteLine("\nИсходный массив: ");
  30.             for (int x = 0; x < arraySize; x++)
  31.             {
  32.                 Console.Write(array[x] + " ");
  33.             }
  34.  
  35.  
  36.             Console.WriteLine("\n\nЛокальные максимумы: ");
  37.             if (array[0] >= array[1])
  38.             {
  39.                 Console.Write(array[0] + " ");
  40.             }
  41.  
  42.  
  43.             for (int x = 1; x < arraySize - 1; x++)
  44.             {
  45.                 if (array[x] >= array[x-1] && array[x] >= array[x+1])
  46.                 {
  47.                     Console.Write(array[x] + " ");
  48.                 }
  49.             }
  50.  
  51.  
  52.             if (array[arraySize-1] >= array[arraySize-2])
  53.             {
  54.                 Console.Write(array[arraySize - 1] + " ");
  55.             }
  56.  
  57.             Console.ReadKey();
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement