二维数组中的某列,vb实现对该列每三个元素求平均值(没有重复的元素),最后显示这些平均值
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/16 01:19:31
二维数组中的某列,vb实现对该列每三个元素求平均值(没有重复的元素),最后显示这些平均值
二维数组中的某列,vb实现对该列每三个元素求平均值(没有重复的元素),最后显示这些平均值
二维数组中的某列,vb实现对该列每三个元素求平均值(没有重复的元素),最后显示这些平均值
Private Sub Command1_Click()
Dim a(6, 10) As Integer
Dim i As Integer
Dim m As Integer
For i = 0 To 10
For m = 0 To 6
a(m, i) = Rnd() * 100
Next
Next
cc a, 3
End Sub
Private Function avg3(ByVal a As Single, ByVal b As Single, ByVal c As Single) As Single
avg3 = a + b + c
avg3 = avg3 / 3
End Function
Private Sub cons(ByVal str As String)
Dim a() As String
Dim i As Integer
Dim ret As String
a = Split(str, ",")
ret = str & vbCrLf
For i = LBound(a) To (UBound(a) - 2)
'Debug.Print a(i)
For m = i + 1 To (UBound(a) - 1)
For n = m + 1 To UBound(a)
ret = ret & a(i) & "," & a(m) & " ," & a(n) & " -- avg:"
ret = ret & avg3(a(i), a(m), a(n))
ret = ret & vbCrLf
Next
Next
Next
MsgBox ret
End Sub
Private Sub cc(ByRef ary2() As Integer, col As Integer)
Dim str As String
For i = LBound(ary2, 1) To UBound(ary2, 1)
If str = "" Then
str = ary2(i, col)
Else
str = str & "," & ary2(i, col)
End If
Next
cons str
End Sub