vb题随机生成【0,100】10个数,选择法排序。

如题所述

Private Sub Command1_Click()

  Dim a(10) As Integer

  For i = 1 To 10

    a(i) = Int(101 * Rnd)

  Next i

  For i = 1 To 9

    k = i

    For j = i + 1 To 10

      If a(j) < a(k) Then k = j

    Next j

    t = a(i): a(i) = a(k): a(k) = t

  Next i

  For i = 1 To 10

    Print a(i);

  Next i

  Print: Print

End Sub

温馨提示:内容为网友见解,仅供参考
第1个回答  推荐于2018-04-13
Dim a(1 To 10) As Integer, zc As Integer
For i = 1 To 10
a(i) = Int(Rnd * 101) '0~100一共101个数,从零开始,所以是int(rnd*101+0),+0省略
Print a(i); '打印原始数据
Next i
Print
For i = 1 To 10
For j = 1 To 9
If a(j + 1) < a(j) Then '如果下标较大的比下标较小的还要小
zc = a(j + 1) '就替换
a(j + 1) = a(j)
a(j) = zc
End If
Next j
Next i
For i = 1 To 10
Print a(i); '打印排序后数据
Next i

如果要在Form中成功打印需要把Form.AutoRedrew设置成True本回答被网友采纳
第2个回答  2014-07-10
Timer1 嗯嗯嗯...

vb题随机生成【0,100】10个数,选择法排序。
Private Sub Command1_Click()Dim a(10) As Integer For i = 1 To 10 a(i) = Int(101 * Rnd)Next i For i = 1 To 9 k = i For j = i + 1 To 10 If a(j) < a(k) Then k = j Next j t = a(i): a(i) = a(k): a(k) = t Next i For i = 1 To 10...

...一百个数字的范围里选十个数字,给这十个数字排序,怎么来
5 4 3 2 1 比如上面这5个数字我们把它按照由小到大的顺序排列,从前往后相临两位比较大小,如果前一位比后一位大就把它俩 换位,5比4大就把5和4换位,得到45321 5又比3大 5和3换位 得到43521 依次类推最后得到 43215 这样就把最大的一个数字移到最后面了 然后不看5 ,剩下4321 再用...

VB中“随机产生10个数,用选择法对10个数进行从小到大排序”要怎么做啊...
Dim arr(0 To 9) As Integer Private Sub Form_Load()Dim i, j, k Randomize For i = 0 To 9 arr(i) = Int(Rnd * 100)Debug.Print arr(i);Next i Debug.Print For i = 0 To 9 k = i For j = i + 1 To 9 If arr(k) > arr(j) Then k = j Next j If k <> ...

随机产生十个10-100的整数,用选择排序法按值从小到大顺序排序,我是学VB...
Private Sub Command1_Click()Dim su(1 To 10) As Integer '定义数组 '产生随机数 For i = 1 To 10 su(i) = Rnd * 90 + 10 '产生10-100的数 Print su(i);Next Print '排序 '这样好像是选择排序吧,先选一个最小的数放在前面 For i = 1 To 9 For j = i To 10 If su(i...

VB选择法排序
Int(100 * Rnd)Print a(i);Next i Print For i = 1 To 9 k = i For j = i + 1 To 10 If a(j) < a(k) Then k = j Next j t = a(i): a(i) = a(k): a(k) = t Next i Print "排序以后的数:"For i = 1 To 10 Print a(i);Next i Print End Sub ...

VB中用选择法将10个整数排序,从小到大排列在另外一个文本框中输出。
Private Sub Command1_Click()Dim A(9) As Integer, i%, m%, t%, AA For i = 0 To 9 Randomize A(i) = Int(Rnd * 90) + 10 Print A(i);Next Print For i = 0 To 8 t = i For m = i + 1 To 9 If A(m) < A(t) Then t = m Next m If t <> i Then AA...

vb选择法排序的怎么做?
Rnd * 100 Next i For i = 1 To 99 k = i For j = i + 1 To 100 If a(j) < a(k) Then k = j Next j t = a(i): a(i) = a(k): a(k) = t Next i For i = 1 To 100 Print Format(a(i), "@@@");If i Mod 10 = 0 Then Print Next i End Sub ...

VB选择法排序
Next i Print '以上十随机得出10个数 For i = 1 To 9 '这里开始是双重循环 For j = i + 1 To 10 If a(i) > a(j) Then '如果前一个数大于后一个数则交换位置 t = a(i): a(i) = a(j): a(j) = t End If Next j Print a(i);Next i Print a(i);End SubI等于1...

简单的VB选择法排序题,急求答案!
你可以用这样的算法:把十个数编进一个数组,然后判断数组内相邻两元素之间的大小,若前一个数大于后一个数,则不做改变;若反之,则交换两个元素的值。具体代码我就不写了吧,手机上不好打代码。反正我遇到这种东西习惯用For...next语句。

vb6.0用选择法对10个整数排列
在VB6.0中,利用选择排序算法对10个整数进行排序,具体过程如下:定义数组a(1 to 10)用于存放10个整数。定义变量maxIndex,用于存储当前未排序部分中的最大值索引。定义变量tmp,用于临时存储交换位置的值。使用两层for循环实现排序过程,外层for循环控制每一趟排序,内层for循环用于查找当前未排序部分中的...

相似回答