Пример #1
0
        /// <summary>
        /// Reads from console the elements for the specified matrix (rows X cols)
        /// </summary>
        /// <param name="rows">The number of rows</param>
        /// <param name="cols">The number of columns</param>
        /// <returns>The matrix filled with read elements</returns>
        private static int[,] ReadMatrixElementsFromConsole(int rows, int cols)
        {
            if (rows < 0)
            {
                rows = 0;
            }

            if (cols < 0)
            {
                cols = 0;
            }

            int[,] matrix = new int[rows, cols];
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    int element = ConsoleHelper.ReadIntegerFromConsole($"Element at [{i},{j}]: ", 0, 10);

                    matrix[i, j] = element;
                }
            }

            return(matrix);
        }
Пример #2
0
        /// <summary>
        /// Reads a general matrix (n X m) from console
        /// </summary>
        /// <returns>The matrix, as read from console</returns>
        public static int[,] ReadFromConsole()
        {
            int rows = ConsoleHelper.ReadIntegerFromConsole("Number of rows: ", 0, 10);

            int cols = ConsoleHelper.ReadIntegerFromConsole("Number of columns: ", 0, 10);

            return(MatrixHelper.ReadMatrixElementsFromConsole(rows, cols));
        }
Пример #3
0
        /// <summary>
        /// Reads a vector from console
        /// </summary>
        /// <returns>The vector filled with elements</returns>
        public static int[] ReadFromConsole()
        {
            int n = ConsoleHelper.ReadIntegerFromConsole("No. of elements: ", 0, 10);

            if (n < 0)
            {
                n = 0;
            }

            var array = new int[n];

            for (int i = 0; i < n; i++)
            {
                int element = ConsoleHelper.ReadIntegerFromConsole($"Element at index {i}: ", 0, 10);

                array[i] = element;
            }

            return(array);
        }
Пример #4
0
        /// <summary>
        /// Reads a square matrix (n X n) from console
        /// </summary>
        /// <returns>The square matrix, as read from console</returns>
        public static int[,] ReadSquareMatrixFromConsole()
        {
            int rows = ConsoleHelper.ReadIntegerFromConsole("Dimension: ", 0, 10);

            return(MatrixHelper.ReadMatrixElementsFromConsole(rows, rows));
        }