asvd32

18

Feb 20th, 2025 (edited)
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.89 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp3
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int size = 30;
  10.             int[] matrix = new int[size];
  11.  
  12.             Random random = new Random();
  13.             int randomMaxRange = 10;
  14.             int randomMinRange = 0;
  15.  
  16.             int step = 1;
  17.             int startPosition = 0;
  18.             int endPosition = matrix.Length - step;
  19.  
  20.             for (int i = 0; i < size; i++)
  21.             {
  22.                 matrix[i] = random.Next(randomMinRange, randomMaxRange);
  23.             }
  24.  
  25.             if (matrix[startPosition] > matrix[startPosition + step])
  26.             {
  27.                 Console.BackgroundColor = ConsoleColor.Green;
  28.                 Console.Write(matrix[startPosition]);
  29.                 Console.ResetColor();
  30.                 Console.Write(" ");
  31.             }
  32.             else
  33.             {
  34.                 Console.Write(matrix[startPosition]);
  35.             }
  36.  
  37.             for (int i = 1; i < size - step; i++)
  38.             {
  39.                 if (matrix[i] > matrix[i + step] && matrix[i] > matrix[i - step])
  40.                 {
  41.                     Console.BackgroundColor = ConsoleColor.Green;
  42.                     Console.Write(matrix[i]);
  43.                     Console.ResetColor();
  44.                     Console.Write(" ");  
  45.                 } else
  46.                 {
  47.                     Console.Write(matrix[i] + " ");
  48.                 }            
  49.             }
  50.  
  51.             if (matrix[endPosition] > matrix[endPosition - step])
  52.             {
  53.                 Console.BackgroundColor = ConsoleColor.Green;
  54.                 Console.Write(matrix[matrix.Length - step]);
  55.                 Console.ResetColor();
  56.                 Console.Write(" ");
  57.             }
  58.             else
  59.             {
  60.                 Console.Write(matrix[matrix.Length - step]);
  61.             }
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment