Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MarmaladeKnight/71ec9a521f07a0a55e713303be32a701 to your computer and use it in GitHub Desktop.
Save MarmaladeKnight/71ec9a521f07a0a55e713303be32a701 to your computer and use it in GitHub Desktop.
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, 12, 12)
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, ByVal n As Integer, ByVal m As Integer)
Dim i, j As Integer
For i = 1 To n
For j = m - i + 1 To m
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