vb 20个100以内的随机整数围成一圈,找出每四个相邻数之和中的最大值,并指出是哪四个相邻的数.格式是一共有3行Text,第一行是显示找出来的20个随机数,第二行是显示四个相邻的最大值,第三行
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/26 17:16:28
vb 20个100以内的随机整数围成一圈,找出每四个相邻数之和中的最大值,并指出是哪四个相邻的数.格式是一共有3行Text,第一行是显示找出来的20个随机数,第二行是显示四个相邻的最大值,第三行
vb 20个100以内的随机整数围成一圈,找出每四个相邻数之和中的最大值,并指出是哪四个相邻的数.
格式是一共有3行Text,第一行是显示找出来的20个随机数,第二行是显示四个相邻的最大值,第三行显示:四个相邻数分别是什么
有四个command键,第一个是“生成数组”,第二个,“寻找”,第三个,“清除”,第四个,“结束”那位VB高手帮帮我这位菜鸟吧.
vb 20个100以内的随机整数围成一圈,找出每四个相邻数之和中的最大值,并指出是哪四个相邻的数.格式是一共有3行Text,第一行是显示找出来的20个随机数,第二行是显示四个相邻的最大值,第三行
Dim ay(20)
Private Sub Command1_Click()
Text1 = ""
For i = 0 To 19
ay(i) = Int(Rnd * 100)
Text1 = Text1 & " " & ay(i)
Next i
End Sub
Private Sub Command2_Click()
'随机数不一定都相邻,只先出四个最大的数
Text2 = ""
Text3 = ""
'用冒泡排序法排序
For i = 19 To 1 Step -1
For j = 0 To i - 1
If ay(j) > ay(j + 1) Then
my = ay(j + 1)
ay(j + 1) = ay(j)
ay(j) = my
End If
Next j
Next i
Text2 = ay(19)
For x = 16 To 19
Text3 = Text3 & ay(x) & " "
Next x
End Sub
Private Sub Command3_Click()
Text1 = ""
Text2 = ""
Text3 = ""
Label1 = ""
End Sub
Private Sub Command4_Click()
End
End Sub
四个相邻数之和的最大值吧?
'===================================================================
'http://zhidao.baidu.com/question/423304664.html?push=related
'============================================================...
全部展开
'===================================================================
'http://zhidao.baidu.com/question/423304664.html?push=related
'===================================================================
'vb 20个100以内的随机整数围成一圈,找出每四个相邻数之和中的最大值,并指出是哪四个相邻的数。 2012-5-14 09:05 提问者: xbc1603 | 浏览次数:21次
'格式是一共有3行Text,第一行是显示找出来的20个随机数,第二行是显示四个相邻的最大值,第三行显示:四个相邻数分别是什么
'有四个command键,第一个是“生成数组”,第二个,“寻找”,第三个,“清除”,第四个,“结束”那位VB高手帮帮我这位菜鸟吧。
'===================================================================
'文本框控件名:20个txtNumb(0-19),4个txtMax4(0-3),1个txtMaxHe
'按钮控件名:cmdRnd、cmdRnd、cmdClear、cmdExit
'[email protected],2012.5.21
'===================================================================
Option Explicit
Dim intArry(19) As Long
Dim intHeAll(19) As Long
Dim strHeAll(19) As String
Dim i As Long
Dim j As Long
Private Sub cmdRnd_Click()
For i = 0 To 19
intArry(i) = Int(Rnd * 100)
txtNumb(i) = intArry(i)
Next
End Sub
Private Sub cmdFind_Click()
Dim intHeMax As Long
Dim strHeMax As String
Dim intHe As Long
Dim strHe As String
Dim strArry() As String
Dim N As Integer
Dim X As Integer
Dim K As Integer
For K = 0 To 3
For j = K To K + 19 Step 4
intHe = 0
strHe = ""
For i = j To j + 3
X = IIf(i <= 19, i, i - 20)
intHe = intHe + intArry(X)
strHe = strHe & " " & intArry(X)
Next
intHeAll(N) = intHe
strHeAll(N) = Trim(strHe)
N = N + 1
Next
Next
For i = 0 To 19
If intHeMax < intHeAll(i) Then
intHeMax = intHeAll(i)
strHeMax = strHeAll(i)
End If
Next
txtMaxHe = intHeMax
strArry() = Split(strHeMax, " ")
For i = 0 To 3
txtMax4(i) = strArry(i)
Next
End Sub
Private Sub cmdClear_Click()
For i = 0 To 19
intArry(i) = 0
txtNumb(i) = ""
Next
For i = 0 To 3
txtMax4(i) = ""
Next
txtMaxHe = ""
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
收起