Option Strict On
Imports System.IO
Module Module1

    Sub Main()
        Dim reader As StreamReader
        reader = New StreamReader("MATRIX.txt")
        Dim line As String = reader.ReadLine()
        Dim p As Integer = line.IndexOf(";")
        Dim N(1) As Integer
        Dim M(1) As Integer
        N(0) = Integer.Parse(line.Substring(0, p))
        M(0) = Integer.Parse(line.Substring(p + 1))
        line = reader.ReadLine()
        N(1) = Integer.Parse(line.Substring(0, p))
        M(1) = Integer.Parse(line.Substring(p + 1))
        Dim A(N(0) - 1, M(0) - 1) As Double
        Dim B(N(1) - 1, M(1) - 1) As Double
        For i = 0 To N(0) - 1
            line = reader.ReadLine()
            For j = 0 To M(0) - 1
                p = line.IndexOf(";")
                A(i, j) = Double.Parse(line.Substring(0, p))
                line = line.Substring(p + 1)
            Next j
        Next i
        line = reader.ReadLine()
        For i = 0 To N(1) - 1
            line = reader.ReadLine()
            For j = 0 To M(1) - 1
                p = line.IndexOf(";")
                B(i, j) = Double.Parse(line.Substring(0, p))
                line = line.Substring(p + 1)
            Next j
        Next i
        If M(0) <> N(1) Then
            Console.WriteLine("    ERROR!!!")
        Else
            Dim C(N(0) - 1, M(1) - 1) As Double
            For j As Integer = 0 To N(0) - 1
                For t As Integer = 0 To M(1) - 1
                    For i As Integer = 0 To M(0) - 1
                        C(j, t) = C(j, t) + A(j, i) * B(i, t)
                    Next i
                Next t
            Next j
            reader.Close()
            Dim writer As StreamWriter
            writer = New StreamWriter("mult.txt")
            writer.WriteLine(" Произведение матриц равно:")
            writer.WriteLine()
            For i As Integer = 0 To N(0) - 1
                writer.WriteLine()
                For j As Integer = 0 To M(1) - 1
                    writer.Write(C(i, j))
                Next j
            Next i
        End If
    End Sub

End Module
