随机产生15个10-100的整数,用选择排序法按值从小到大顺序排序,我是学VB的。急急。。。我要具体的方法

2024-12-29 15:48:33
推荐回答(3个)
回答1:

Dim A() As Integer
'定义数组
ReDim A(1 To 15)
'分配空间
For i = 1 To 15
A(i) = Fix(Rnd * 91 + 10)
Next i
'生成随机数
For i = 1 To 14
m = i
For j = i + 1 To 15
If A(j) < A(m) Then m = j
Next j
q = A(m)
A(m) = A(i)
A(i) = q
Next i
'排序
For i = 1 To 15
Print A(i),
Next i
'输出

回答2:

难得写~~先用rnd*100-10把数定义在15位数字里面
然后用冒泡法排序 n-1和n比较 大了交换位置

回答3:

http://tieba.baidu.com/f?ct=352321536&tn=bdAdvResult&rn=10&pn=0&lm=65536&cm=0&kw=&rs2=1&sc=&un=&rs1=0&rs5=1&sn=vb&rs6=0&myselectvalue=0&word=%C5%C5%D0%F2+%CA%FD%D7%D6&tb=on