1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | using System; namespace CyberForum { class Program { static void Main() { Random rand = new Random(); const int n = 10; int [,] matrix = new int [n, n]; for ( int i = 0; i < n; i++) { for ( int j = 0; j < n; j++) { matrix[i, j] = rand.Next(0, 1000); } } Func< int , int , bool > inLeftTopSquare = (y, x) => x < n / 2 && y < n / 2; Func< int , int , bool > inRightBottom = (y, x) => x >= n / 2 && x <= y; Func< int , int , bool > inLeftBottom = (y, x) => y >= n / 2 && x < n - y; int maxElement = matrix[0, 0]; for ( int y = 0; y < n; y++) { for ( int x = 0; x < n; x++) { if (matrix[y, x] > maxElement) maxElement = matrix[y, x]; if (inLeftTopSquare(y, x)) Console.ForegroundColor = ConsoleColor.Red; else if (inRightBottom(y, x)) Console.ForegroundColor = ConsoleColor.Green; else if (inLeftBottom(y, x)) Console.ForegroundColor = ConsoleColor.Blue; Console.Write(matrix[y, x].ToString().PadLeft(5)); Console.ResetColor(); } Console.WriteLine(); } Console.WriteLine( "\nМаксимальный элемент: " + maxElement); } } } |