@embiid

Как вывести значение матрицы?

Подскажите, как в функции DisplayMatrix, вывести уже созданную матрицу?
Мне выводит нули.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Vector {
    protected int row, column;
    protected int[,] ARRAY;

    protected int ROW {
        get { return row; }
        set { row = value; }
    }

    protected int COLUMN {
        get { return column; }
        set { column = value; }
    }

    public Vector() {

    }

    public Vector(int row, int column) {
        this.row = ROW;
        this.column = COLUMN;

        ARRAY = new int[this.COLUMN, this.ROW];
    }

    public void EnterVector() {
        Console.WriteLine("Choose type of vector:" +
                          "\nvector-row = [1]"     +
                          "\nvector-col = [2]"     );
        int variant = int.Parse(Console.ReadLine());

        if (variant == 1) {
            COLUMN = 1;
            Console.Write("Enter the numbers of vector elements: ");
            ROW = int.Parse(Console.ReadLine());
        }
        else if (variant == 2) {
            ROW = 1;
            Console.WriteLine("Enter the numbers of vectror elements: ");
            COLUMN = int.Parse(Console.ReadLine());
        }
        
        for (int col = 0; col < COLUMN; col++) {
            for (int row = 0; row < ROW; row++) {
                Console.Write("Enter the element of matrix cell[" + (col + 1) + ":" + (row + 1) + "]: ");
                int.Parse(Console.ReadLine());
            }
        }
    }

    /*public void ARRAYxARRAY(int[,] firstMatrix, int[,] secondMatrix, int[,] mult, int rowFirst, int columnFirst, int rowSecond, int columnSecond) {
        for (int i = 0; i < rowFirst; i++) {
            for (int j = 0; j < columnSecond; j++) {
                mult[i, j] = 0;
            }
        }

        for (int i = 0; i < rowFirst; i++) {
            for (int j = 0; j < columnSecond; j++) {
                for (int k = 0; k < columnFirst; k++) {
                    mult[i, j] += firstMatrix[i, k];
                }
            }
        }
    }*/

    /*public void ARRAYxARRAY(int m, int n, int p, int[,] frstMatrix, int[,] scndMatrix, int[,] mult) {
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < p; j++) {
                mult[i, j] = 0;
                for (int k = 0; k < n; k++) {
                    mult[i, j] += frstMatrix[i, k] * scndMatrix[k, j];
                }
            }
        }
    }*/

    ~Vector() {
        Console.WriteLine("Vector has been denied.");
    }
}

class Matrix : Vector { 
    public Matrix() {

    }

    public Matrix(int row, int column) {
        this.row = ROW;
        this.column = COLUMN;

        ARRAY = new int[this.COLUMN, this.ROW];
    }

    public void EnterMatrix() {
        Console.Write("Enter the numbers of matrix columns: ");
        COLUMN = int.Parse(Console.ReadLine());
        Console.Write("Enter the numbers of matrix rows: ");
        ROW = int.Parse(Console.ReadLine());

        ARRAY = new int[COLUMN, ROW];
        
        for (int col = 0; col < COLUMN; col++) {
            for (int row = 0; row < ROW; row++) {
                Console.Write("Enter the element of matrix cell[" + (col + 1) + ":" + (row + 1) + "]: ");
                int.Parse(Console.ReadLine());
            }
        }
    }

    public void DisplayMatrix() {
        Console.Write("\nThe matrix is: ");
        for (int j = 0; j < COLUMN; j++) {
            Console.WriteLine("\n");
            for (int k = 0; k < ROW; k++) {
                Console.Write("{0}\t", ARRAY[j, k]);
            }
        }
        Console.WriteLine();
    }

    ~Matrix() {
        Console.WriteLine("Matrix has been denied.");
    }
}

class Program {
    static void Main() {
        Vector VECTOR = new Vector();
               VECTOR.EnterVector();
             //VECTOR.Display();

        Console.WriteLine("");

        Matrix MATRIX = new Matrix();
               MATRIX.EnterMatrix();
               MATRIX.DisplayMatrix();
    }
}
  • Вопрос задан
  • 117 просмотров
Решения вопроса 1
@assembled
public void EnterMatrix() {
        Console.Write("Enter the numbers of matrix columns: ");
        COLUMN = int.Parse(Console.ReadLine());
        Console.Write("Enter the numbers of matrix rows: ");
        ROW = int.Parse(Console.ReadLine());

        ARRAY = new int[COLUMN, ROW];
        
        for (int col = 0; col < COLUMN; col++) {
            for (int row = 0; row < ROW; row++) {
                Console.Write("Enter the element of matrix cell[" + (col + 1) + ":" + (row + 1) + "]: ");
                ARRAY [ col , row ] = int.Parse(Console.ReadLine()); // тута ошибка
            }
        }
    }

Вы значение вводите, но нигде не сохраняете.
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы