标题:我真是小白,哪位大佬出手相助
只看楼主
YMH030109
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2020-3-23
结帖率:0
已结贴  问题点数:20 回复次数:3 
我真是小白,哪位大佬出手相助
随机产生10个50以内的正整数,从大到小排序,并显示排序前和排序后的结果。
搜索更多相关主题的帖子: 显示 结果 排序 从大到小 正整数 
2020-03-23 18:21
YMH030109
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2020-3-23
得分:0 
随机产生10个50以内的正整数,从大到小排序,并显示排序前和排序后的结果
2020-03-23 20:57
HVB6
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:15
帖 子:320
专家分:561
注 册:2013-10-30
得分:10 

Private Sub test()
   Dim i As Integer
    Dim j As Integer
    Dim a(10) As Integer
    Dim s, s1
    For i = 1 To 10
        a(i) = Round(Rnd * 50, 0) + 1
        For j = 1 To i - 1
        If a(i) = a(j) Then
              i = i - 1
        
        End If
        Next j
       '  Range("a" & i) = a(i) '去掉此行的第一个注释符号,此代码可在Excl的代码区运行。
        s = s & "," & a(i)
    Next i
      MsgBox s  '显示数组
        M = 1
For i = 1 To 9
If a(i) >= a(i + 1) Then
  If i > M Then
   M = i
  Else
   i = M
  End If
  GoTo kk:
Else
x = a(i)
a(i) = a(i + 1)
a(i + 1) = x
If i <> 1 Then i = i - 2
End If
kk:
Next i
  For i = 1 To 10
    ' Range("b" & i) = a(i)   '去掉此行的第一个注释符号,此代码可在Excl的代码区运行。
    s1 = s1 & "," & a(i)
Next i
     MsgBox s1  '显示数组
End Sub
2020-03-24 08:31
ZHRXJR
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:125
帖 子:1034
专家分:5519
注 册:2016-5-10
得分:10 

程序代码:
Dim AA(1 To 10) As Integer, BB(1 To 10) As Integer

Private Sub Command1_Click()
For I = 1 To 10
    BB(I) = AA(I)
Next I
Dim KK As Integer
For I = 1 To 9
    For J = 1 To 10 - I
        If BB(J) > BB(J + 1) Then
            KK = BB(J)
            BB(J) = BB(J + 1)
            BB(J + 1) = KK
        End If
    Next J
Next I
Text2.Text = ""
For I = 1 To 10
    If BB(I) < 10 Then
        Text2.Text = Text2.Text & "0" & CStr(BB(I)) & Space(5)
    Else
        Text2.Text = Text2.Text & CStr(BB(I)) & Space(5)
    End If
Next I
End Sub

Private Sub Command2_Click()
Unload Me
Form1.Show
End Sub

Private Sub Form_Load()
For I = 1 To 10
    Randomize
    AA(I) = Int(Rnd * 50 + 1)
Next I
Text1.Text = ""
For I = 1 To 10
    If AA(I) < 10 Then
        Text1.Text = Text1.Text & "0" & CStr(AA(I)) & Space(5)
    Else
        Text1.Text = Text1.Text & CStr(AA(I)) & Space(5)
    End If
Next I
End Sub

请不要选我!!!
2020-03-27 17:01



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-500536-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021967 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved