Vb 用自定义函数求数组最大值!求帮助! 10
用随机函数生成一个有10个人100~200之间元素的数组,在label1中显示,使用自定义函数来求数组中最大元素,在label2种显示!...
用随机函数生成一个有10个人100~200之间元素的数组,在label1中显示,使用自定义函数来求数组中最大元素,在label2种显示!
展开
展开全部
Private Sub Command2_Click()
Dim i As Integer
Dim s As String
Randomize
For i = 0 To 9
a(i) = Rnd * 100 + 100
s = s & Str(a(i))
Next i
Label1.Caption = s
End Sub
Private Function GetMax() As Integer
Dim i As Integer
Dim imax As Integer
For i = 0 To 9
If a(i) > imax Then imax = a(i)
Next i
GetMax = imax
End Function
Private Sub Command3_Click()
Label2.Caption = Str(GetMax)
End Sub
Dim i As Integer
Dim s As String
Randomize
For i = 0 To 9
a(i) = Rnd * 100 + 100
s = s & Str(a(i))
Next i
Label1.Caption = s
End Sub
Private Function GetMax() As Integer
Dim i As Integer
Dim imax As Integer
For i = 0 To 9
If a(i) > imax Then imax = a(i)
Next i
GetMax = imax
End Function
Private Sub Command3_Click()
Label2.Caption = Str(GetMax)
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Function max(d() As Integer)
s = 0
For i = 0 To UBound(d) - LBound(d)
If s < d(i) Then s = d(i)
Next
max = s
End Function
Private Sub Command1_Click()
Label1.Caption = ""
Dim d(10) As Integer
For i = 0 To 10
Randomize
d(i) = Int(Rnd * 101 + 100)
Label1.Caption = Label1.Caption & " " & d(i)
Next
Label2.Caption = max(d)
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
等等,我算算
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |