VB 排列大小序

来源:百度知道 编辑:UC知道 时间:2024/05/27 03:41:56
请问下列这些数字怎样按从小到大的顺序排列!
74 85 69 32 15 46 59

Private Sub Command1_Click()
Dim i As Integer, n As Integer, a() As Integer, j As Integer, t As Integer
n = InputBox("请输入你要排列的数的个数")
ReDim a(n)
For i = 1 To n
a(i) = InputBox("输入排列大小的数字")
Next i
For i = 1 To UBound(a) - 1
For j = i + 1 To UBound(a)
If a(i) > a(j) Then
t = a(i)
a(i) = a(j)
a(j) = t
End If
Next j
Next i
For i = 1 To UBound(a)
Print a(i)
Next i

End Sub

VB6.0的话,就这么写:
dim a
a=array(74, 85, 69, 32, 15, 46, 59)
dim i,j,k as integer
for i=0 to ubound(a)-1
for j =i+1 to ubound(a)
if a(i)>a(j) then
k=a(i)
a(i)=a(j)
a(j)=k
end if
next
next
如果你用的是VB2005的话,就更简单了,两句代码解决问题:
dim a as integer()=new integer(){74, 85, 69, 32, 15, 46, 59}
array.sort(a)

数字排序有很多方法,很多地方(如教材)上都有的“气泡排序法”就是一个非常好用的方法,你可以看一下。