Private Sub Ave(Arry() As Integer,ByVal N As Integer,Average As Integer)
Dim I As Integer,Sum As Integer
Sum = 0
For I = 1 To N - 1
Sum = Sum + Arry(I)
Next I
Average = Sum / N
End Sub
Private Sub Max(Arry() As Integer,M As Integer)
Dim I As Integer
M = Arry(0)
For I = 1 To N - 1
If Arry(I) > M Then
M = Arry(I)
End If
Next I
End Sub
Private Sub Sort(Arry() As Integer,ByVal N As Integer)
Dim I As Integer,J As Integer,K As Integer,Temp As Integer
For I = 0 To N - 2
K = I
For J = I + 1 To N - 1
If Arry(K) > Arry(J) Then
K = J
End If
Next J
If K > I Then
Temp = Arry(K)
Arry(K) = Arry(I)
Arry(I) = Temp
End If
Next I
End Sub
Private Sub Command1_Click() Dim Arra(10) As Integer,I As Integer,Average As Integer,Maxm As Integer For I = 0 To 9 Arra(I) = Rnd * 100 Print Arra(I); " "; Next I Print Call Sort(Arra,10) For I = 0 To 9 Print Arra(I); " "; Next I Print Call Max(Arra,10,Maxm) Call Ave(Arra,Average) Print "Max="; Maxm,"Ave="; Average Print End Sub
原文链接:https://www.f2er.com/vb/259098.html