Created
March 10, 2019 09:35
-
-
Save MarmaladeKnight/cb1f105034b62add39c6f2c4c9761989 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Class Form1 | |
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click | |
Dim array(12, 12), sum, count As Integer | |
sum = 0 | |
count = 0 | |
randArray(array, 12, 12) | |
output(array, ListBox1) | |
countSumOfPositiveValues(array, sum, count) | |
addSumToArrayElements(array, sum) | |
output(array, ListBox2) | |
output(sum, TextBox1) | |
output(count, TextBox2) | |
End Sub | |
Sub randArray(ByRef arr(,) As Integer, ByVal m As Integer, ByVal n As Integer) | |
Dim i, j As Integer | |
Randomize() | |
For i = 0 To m | |
For j = 0 To n | |
arr(i, j) = CInt(10 * Rnd()) - 3 | |
Next | |
Next | |
End Sub | |
Sub countSumOfPositiveValues(ByVal arr(,) As Integer, ByRef sum As Integer, ByRef count As Integer) | |
Dim i, j As Integer | |
For i = 1 To 12 | |
For j = 12 - i + 1 To 12 | |
If arr(i, j) > 0 Then | |
sum += arr(i, j) | |
count += 1 | |
End If | |
Next | |
Next | |
End Sub | |
Sub addSumToArrayElements(ByRef arr(,) As Integer, ByVal sum As Integer) | |
Dim i, j As Integer | |
For i = 0 To 12 | |
For j = 0 To 12 | |
arr(i, j) += sum | |
Next | |
Next | |
End Sub | |
Overloads Sub output(ByVal array(,) As Integer, ByVal Output As ListBox) | |
Dim i, j As Integer | |
Dim tmpStr As String = "" | |
For i = 0 To 12 | |
For j = 0 To 12 | |
tmpStr += CStr(array(i, j)) + " " | |
Next | |
Output.Items.Add(tmpStr) | |
tmpStr = "" | |
Next | |
End Sub | |
Overloads Sub output(ByVal value As Integer, ByVal Output As TextBox) | |
Output.Text = CStr(value) | |
End Sub | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment