Hello. I am trying to find out how to declare the variables and make the functio
ID: 3621202 • Letter: H
Question
Hello. I am trying to find out how to declare the variables and make the functions to add, subtract, and multiply two matrices together. As well as Transpose and Printing values from a given matrix. This is using Microsoft Visual Studio.I tried this, but the program did not work. I am not sure what I am doing wrong. You can rewrite a new program for me or you can fix my code. Thank You and I will Rate!
Sub Main()
Dim A(1, 1) As Integer
Dim B(1, 1) As Integer
A(0, 0) = 1
A(0, 1) = 5
A(1, 0) = 4
A(1, 1) = 7
B(0, 0) = 5
B(0, 1) = 8
B(1, 0) = 9
B(1, 1) = 3
InputBox("What operation do you want to complete?")
End Sub
Function AddTwoMatrices(ByVal A, ByVal B) As Array
Dim matrix(1, 1) As Integer
For i = 0 To 1
For j = 0 To 1
matrix(i, j) = A(i, j) + B(i, j)
Next
Next
MsgBox("The solution is ")
MsgBox(matrix)
End Function
Function SubtractTwoMatrices(ByVal A, ByVal B) As Array
Dim matrix(1, 1) As Integer
For i = 0 To 1
For j = 0 To 1
matrix(i, j) = A(i, j) - B(i, j)
Next
Next
MsgBox("The solution is ")
MsgBox(matrix)
End Function
Function MultiplyTwoMatrices(ByVal A, ByVal B) As Array
Dim matrix(1, 1) As Integer
For i = 0 To 1
For j = 0 To 1
matrix(i, j) = A(i, j) * B(i, j)
Next
Next
MsgBox("The solution is ")
MsgBox(matrix)
End Function
Function TransposeMatrix(ByVal A) As Array
End Function
Function PrintMatrix(ByVal A) As Array
Dim values As String
Dim row1
Dim column1
Dim Matrix2
For i = 0 To column1
For j = 0 To row1
values = values & " " & Matrix2(i, j)
Next
Debug.Print(values)
values = ""
Next
End Function
Explanation / Answer
Imports System.IO
Module Module1
Sub Main()
Dim A(1, 1) As Integer
A(0, 0) = 1
A(0, 1) = 5
A(1, 0) = 4
A(1, 1) = 7
Dim B(1, 1) As Integer
B(0, 0) = 5
B(0, 1) = 8
B(1, 0) = 9
B(1, 1) = 3
Dim choice As String
Console.WriteLine("enter choice:")
choice = Convert.ToChar(Console.ReadLine())
Select Case (choice)
Case "+"
AddTwoMatrices(A, B)
Case "-"
SubtractTwoMatrices(A, B)
Case "*"
MultiplyTwoMatrices(A, B)
End Select
End Sub
Function AddTwoMatrices(ByVal A, ByVal B) As Array
Dim C(1, 1) As Integer
Dim i, j As Integer
For i = 0 To 1
For j = 0 To 1
C(i, j) = A(i, j) + B(i, j)
Next
Next
PrintMatrix(C)
End Function
Function SubtractTwoMatrices(ByVal A, ByVal B) As Array
Dim C(1, 1) As Integer
Dim i, j As Integer
For i = 0 To 1
For j = 0 To 1
C(i, j) = A(i, j) - B(i, j)
Next
Next
PrintMatrix(C)
End Function
Function MultiplyTwoMatrices(ByVal A, ByVal B) As Array
Dim C(1, 1) As Integer
Dim i, j As Integer
For i = 0 To 1
For j = 0 To 1
C(i, j) = A(i, j) * B(i, j)
Next
Next
PrintMatrix(C)
End Function
Function TransposeMatrix(ByVal A) As Array
End Function
Function PrintMatrix(ByVal C) As Array
Dim values As String
Dim i, j As Integer
For i = 0 To 1
For j = 0 To 1
Console.Write(C(i, j))
Console.Write(Space(2))
Next
Console.WriteLine()
Next
Console.ReadLine()
End Function
End Module
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.