Beispiel #1
0
        static void Main(string[] args)
        {
            int numberOfRows    = ReadInt("number of rows is:");
            int numberOfColumns = ReadInt("number of columns is: ");

            int[,] matrix = CreateRandomMatrix(numberOfRows, numberOfColumns);
            int[]          arrayOfCurrentLine   = new int[numberOfColumns];
            int[]          arrayOfcurrentColumn = new int[numberOfRows];
            int            currentElement       = 0;
            bool           isItElement          = false;
            TryFindElement tryFindElement       = new TryFindElement(currentElement, isItElement);
            int            countElements        = 0;

            for (int j = 0; j < numberOfRows; j++)
            {
                int k = 0;

                while (k != numberOfColumns)
                {
                    tryFindElement = TryFindElement(matrix, j, k, numberOfRows, numberOfColumns);
                    if (tryFindElement.Successes)
                    {
                        Console.WriteLine($"{tryFindElement.Element}:{k}, {j}");
                        countElements++;
                    }
                    k++;
                }
            }

            if (countElements == 0)
            {
                Console.WriteLine(countElements);
            }
            Console.ReadKey();
        }
Beispiel #2
0
        static TryFindElement TryFindElement(int[,] matrix, int indexOfRow, int indexOfColumn, int numberOfRows, int numberOfColumns)
        {
            int            element        = 0;
            bool           successes      = false;
            TryFindElement tryFindElement = new TryFindElement(element, successes);

            int[] currentArrayOfRow = GetArrayOfTheRow(indexOfRow, matrix, numberOfColumns);
            bool  isItMaxElement    = IsItMaxElementInRow(currentArrayOfRow, indexOfColumn);

            if (isItMaxElement)
            {
                int[] currentArrayOfColumn = GetArrayOfTheColumn(indexOfColumn, matrix, numberOfRows);
                bool  isItMaxAndMinElement = IsItMinElementInTheColumn(currentArrayOfColumn, indexOfRow);

                if (isItMaxAndMinElement)
                {
                    successes = true;
                    element   = matrix[indexOfColumn, indexOfRow];
                    Console.WriteLine(indexOfColumn);
                    Console.WriteLine(indexOfRow);
                }
            }
            tryFindElement.Element   = element;
            tryFindElement.Successes = successes;

            return(tryFindElement);
        }