Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.IO
- Module Module1
- Sub Main()
- Dim X(,), Y(,) As Double
- Dim M As Integer, N As Integer
- Dim i As Integer, j As Integer
- Dim compute As String
- Dim startFile As Boolean
- Console.WriteLine("Do you want to open file [Y]es/[N]o")
- compute = Console.ReadLine()
- If compute = "Y" Then
- startFile = True
- Else
- startFile = False
- End If
- If startFile Then
- Dim dataReturn = readFile(M, N, X, Y)
- M = dataReturn.item1
- N = dataReturn.item2
- X = dataReturn.item3
- Y = dataReturn.item4
- Else
- Dim dataReturn = readFromConsole(M, N, X, Y)
- M = dataReturn.item1
- N = dataReturn.item2
- X = dataReturn.item3
- Y = dataReturn.item4
- End If
- printResult(M, N, X, Y)
- End Sub
- 'read file form location
- Function readFile(M As Double, N As Double, X(,) As Double, Y(,) As Double)
- Dim fileLocation As String
- Console.WriteLine("Insert file location:")
- fileLocation = Console.ReadLine()
- 'fileLocation = "test.txt" 'remove for production
- Dim reader As StreamReader = My.Computer.FileSystem.OpenTextFileReader(fileLocation)
- M = reader.ReadLine
- Console.WriteLine("M count: " & M)
- N = reader.ReadLine
- Console.WriteLine("N count: " & N)
- ReDim X(M, N)
- For i = 1 To M
- For j = 1 To N
- X(i, j) = reader.ReadLine
- Next j
- Next i
- ReDim Y(M, N)
- For i = 1 To M
- For j = 1 To N
- Y(i, j) = reader.ReadLine
- Next j
- Next i
- reader.Close()
- Return (M, N, X, Y)
- End Function
- 'read data form console
- Function readFromConsole(M As Integer, N As Integer, X(,) As Double, Y(,) As Double)
- Do
- Console.Write("M=")
- M = Console.ReadLine()
- Loop Until M > 1 And M <= 10
- Do
- Console.Write("N=")
- N = Console.ReadLine()
- Loop Until N > 1 And N <= 10
- ReDim X(M, N)
- For i = 1 To M
- For j = 1 To N
- Console.Write("X(" & i & "," & j & "): ")
- X(i, j) = Console.ReadLine()
- Next j
- Next i
- ReDim Y(M, N)
- For i = 1 To M
- For j = 1 To N
- Console.Write("Y(" & i & "," & j & "): ")
- Y(i, j) = Console.ReadLine()
- Next j
- Next i
- Return (M, N, X, Y)
- End Function
- 'print data function
- Function printResult(M As Integer, N As Integer, X(,) As Double, Y(,) As Double)
- Dim Z(,) As Double
- ReDim Z(M, N)
- For i = 1 To M
- For j = 1 To N
- If (i + j) Mod 2 = 0 Then ' i+j e chetno
- Z(i, j) = X(i, j) + Y(i, j)
- Else ' i+j e nechetno
- Z(i, j) = X(i, j) - Y(i, j)
- End If
- Next j
- Next i
- Console.WriteLine("Матрица Z(M,N):")
- For i = 1 To M
- For j = 1 To N
- Console.Write(Z(i, j) & " ")
- Next j
- Console.WriteLine()
- Next i
- Console.ReadLine() 'za da spre programata i da moje da se vidi krainiqt rezultat
- End Function
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement