VB编程:分别求出数组中取得最大值和最小值的元素个数,并在窗体上显示
例如:0034121134343434在这个随机产生的数列中,要求出最大值34的元素为4,最小值0的元素为2,并在窗体上显示,如何用VB语言编程?...
例如:
0 0 3 4 12
11 34 34 34 34
在这个随机产生的数列中,要求出最大值34的元素为4,最小值0的元素为2,并在窗体上显示,如何用VB语言编程? 展开
0 0 3 4 12
11 34 34 34 34
在这个随机产生的数列中,要求出最大值34的元素为4,最小值0的元素为2,并在窗体上显示,如何用VB语言编程? 展开
1个回答
展开全部
Private Sub Form_Click()
Form1.AutoRedraw = True
Dim A()
Dim I As Integer, J As Integer, N As Integer
Dim MinG As Integer, MaxG As Integer
A = Array(0, 0, 3, 4, 12, 11, 34, 34, 34, 34)
For I = 0 To UBound(A) - 1
For J = I To UBound(A)
If A(I) > A(J) Then
N = A(I)
A(I) = A(J)
A(J) = N
End If
Next
Next
MinG = 1
MaxG = 1
For I = 1 To UBound(A) - 1
If A(I) = A(0) Then MinG = MinG + 1
If A(I) = A(UBound(A)) Then MaxG = MaxG + 1
Next
Print "数组为:"
For I = 0 To UBound(A())
Print A(I);
Next
Print
Print "其中最小的元素为:"; A(0); ",个数为:"; MinG
Print "其中最大的元素为:"; A(UBound(A)); ",个数为:"; MaxG
End Sub
已经运行过。
Form1.AutoRedraw = True
Dim A()
Dim I As Integer, J As Integer, N As Integer
Dim MinG As Integer, MaxG As Integer
A = Array(0, 0, 3, 4, 12, 11, 34, 34, 34, 34)
For I = 0 To UBound(A) - 1
For J = I To UBound(A)
If A(I) > A(J) Then
N = A(I)
A(I) = A(J)
A(J) = N
End If
Next
Next
MinG = 1
MaxG = 1
For I = 1 To UBound(A) - 1
If A(I) = A(0) Then MinG = MinG + 1
If A(I) = A(UBound(A)) Then MaxG = MaxG + 1
Next
Print "数组为:"
For I = 0 To UBound(A())
Print A(I);
Next
Print "其中最小的元素为:"; A(0); ",个数为:"; MinG
Print "其中最大的元素为:"; A(UBound(A)); ",个数为:"; MaxG
End Sub
已经运行过。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询