public static void Main()
    {
        MatrixMultiplication MM = new MatrixMultiplication();

        MM.ReadMatrix();
        MM.MultiplyMatrix();
        MM.PrintMatrix();
    }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            int[,] Matrix_1, Matrix_2;
            string[] FileString;
            int      M1, N1 = 0, M2, N2;

            using (var file = new StreamReader(Path.GetFullPath("Inlet.txt")))
            {
                int      i;
                string[] Aux;
                string   CheckString = "";
                for (i = 0; ; i++)
                {
                    CheckString = file.ReadLine();
                    if (CheckString == "------")
                    {
                        break;
                    }
                    N1 = CheckString.Split(' ').Length;
                }
                M1 = i;
                for (i = 0; !file.EndOfStream; i++)
                {
                    CheckString = file.ReadLine();
                }
                M2  = i;
                Aux = CheckString.Split(' ');
                N2  = Aux.Length;
                file.Close();
            }
            using (var file = new StreamReader(Path.GetFullPath("Inlet.txt")))
            {
                Matrix_1 = new int[M1, N1];
                int i, j;
                for (i = 0; i < M1; i++)
                {
                    FileString = file.ReadLine().Split(' ');
                    for (j = 0; j < N1; j++)
                    {
                        Matrix_1[i, j] = int.Parse(FileString[j]);
                    }
                }
                file.ReadLine();
                Matrix_2 = new int[M2, N2];
                for (i = 0; i < M2; i++)
                {
                    FileString = file.ReadLine().Split(' ');
                    for (j = 0; j < N2; j++)
                    {
                        Matrix_2[i, j] = int.Parse(FileString[j]);
                    }
                }
            }
            Matrix Matrix1 = new Matrix(Matrix_1, M1, N1);
            Matrix Matrix2 = new Matrix(Matrix_2, M2, N2);
            Matrix MatrixSum, MatrixMultiplication, MatrixDifferent;

            MatrixSum            = Matrix.Summ(Matrix1, Matrix2);
            MatrixDifferent      = Matrix.Diff(Matrix1, Matrix2);
            MatrixMultiplication = Matrix.Multipication(Matrix1, Matrix2);
            Console.WriteLine("Сумма двух матриц: ");
            MatrixSum.PrintMatrix();
            Console.WriteLine();
            Console.WriteLine("Разность двух матриц: ");
            MatrixDifferent.PrintMatrix();
            Console.WriteLine();
            Console.WriteLine("Произведение двух матриц: ");
            MatrixMultiplication.PrintMatrix();
        }