Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ExamPractice
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- int[,] array = new int[n, n];
- array = ReadArray(n, array);
- IsRowsSorted(n, array);
- IsColsSorted(n, array);
- BiggestNumberinDiagonal(n, array);
- CountOfDiagonalNumbers(n, array);
- }
- private static void IsColsSorted(int n, int[,] array)
- {
- bool isColsSorted = true;
- for (int col = 0; col < n; col++)
- {
- for (int row = 1; row < n; row++)
- {
- if (array[row, col] < array[row - 1, col])
- {
- isColsSorted = false;
- break;
- }
- }
- }
- if (isColsSorted)
- {
- Console.WriteLine("Всички колони са сортирани.");
- }
- else
- {
- Console.WriteLine("Колоните на матрицата не са сортирани");
- }
- }
- private static void IsRowsSorted(int n, int[,] array)
- {
- bool isRowsSorted = true;
- for (int row = 0; row < n; row++)
- {
- for (int col = 1; col < n; col++)
- {
- if (array[row, col] < array[row, col - 1])
- {
- isRowsSorted = false;
- break;
- }
- }
- }
- if (isRowsSorted)
- {
- Console.WriteLine("Всички редове са сортирани.");
- }
- else
- {
- Console.WriteLine("Редовете на матрицата не са сортирани");
- }
- }
- private static int[,] ReadArray(int n, int[,] array)
- {
- for (int row = 0; row < n; row++)
- {
- for (int col = 0; col < n; col++)
- {
- array[row, col] = int.Parse(Console.ReadLine());
- }
- }
- return array;
- }
- private static void BiggestNumberinDiagonal(int n, int[,] array)
- {
- for (int row = 0; row < n; row++)
- {
- bool isMax = true;
- for (int col = 0; col < n; col++)
- {
- int diagonalElement = array[row, row];
- if (array[row, col] > diagonalElement)
- {
- isMax = false;
- }
- }
- if (isMax)
- {
- Console.WriteLine($"Елементът на гравният диагонал на ред {row} е най-големият за реда");
- }
- }
- }
- private static void CountOfDiagonalNumbers(int n, int[,] array)
- {
- int count = 0;
- for (int row = 0; row < n; row++)
- {
- int leftDiagonalNumber = array[row, row];
- if (leftDiagonalNumber > 0 && leftDiagonalNumber % 2 == 0)
- {
- count++;
- }
- int rightDiagonalNumber = array[n - row - 1, n - row - 1];
- if (rightDiagonalNumber > 0 && rightDiagonalNumber % 2 == 0)
- {
- count++;
- }
- }
- Console.WriteLine($"Елементите на диагоналите които са положителни и четни са {count} броя");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement