Advertisement
SaNik74

local max

Apr 6th, 2024 (edited)
812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. internal class Program
  2. {
  3.     static void Main(string[] args)
  4.     {
  5.         Random random = new Random();
  6.         int minValueRandomNumber = 1;
  7.         int maxValueRandomNumber = 10;
  8.         int numberOfNumbers = 30;
  9.         int[] numbersInLine = new int[numberOfNumbers];
  10.         int lastNumberInLine = numbersInLine.Length - 1;
  11.  
  12.         for (int i = 0; i < numberOfNumbers; i++)
  13.         {
  14.             numbersInLine[i] = random.Next(minValueRandomNumber, maxValueRandomNumber);
  15.             Console.Write(numbersInLine[i] + " ");
  16.         }
  17.  
  18.         Console.WriteLine();
  19.  
  20.         if (numbersInLine[0] > numbersInLine[1])
  21.         {
  22.             Console.Write(numbersInLine[0] + " ");
  23.         }
  24.  
  25.         for (int i = 1; i < numbersInLine.Length - 1; i++)
  26.         {
  27.             if (numbersInLine[i] > numbersInLine[i - 1] && numbersInLine[i] > numbersInLine[i + 1])
  28.             {
  29.                 Console.Write(numbersInLine[i] + " ");
  30.                 i++;
  31.             }
  32.         }
  33.  
  34.         if (numbersInLine[lastNumberInLine] > numbersInLine[lastNumberInLine - 1])
  35.         {
  36.             Console.Write(numbersInLine[lastNumberInLine]);
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement