在窗体上增加一个按钮,双击按钮,粘贴以下代码,运行即可:
Dim s(10), t As Long
Print "以下为原数组:"
For i = 1 To 10
s(i) = Val(InputBox("输入整数", "输入"))
Print s(i)
Next i
For i = 1 To 10
For j = i To 9
If s(i) > s(j + 1) Then
t = Val(s(i))
s(i) = Val(s(j + 1))
s(j + 1) = t
End If
Next j
Next i
Print "以下为排序后数组:"
For i = 1 To 10
Print s(i)
Next i
'冒泡排序,最简单的排序算法,下面这个子过程是对Integer类型的数组升序排序,如果需要其他类型的数据,可以将其中的Integer替换掉
Sub MaoPaoSort(a() As Integer)
Dim i As Integer
Dim j As Integer
Dim temp As Integer
For i = LBound(a()) To UBound(a()) - 1
For j = LBound(a()) To UBound(a()) - 1
If a(j) > a(j + 1) Then
temp = a(j)
a(j) = a(j + 1)
a(j + 1) = temp
End If
Next
Next
End Sub
Private Sub Command1_Click()
Dim a(10) As Integer
Randomize
For i = 1 To 10
a(i) = Int(Rnd 900) + 100
Print a(i);
Next i
Print: Print
Print "排序后:"
For i = 1 To 9
For j = 1 To 10 - i
If a(j) < a(j + 1) Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
End If
Next j
Next i
For i = 1 To 10
Print a(i);
Next i
End Sub
以上就是关于用VB编写程序。题如下:随便输入10个正整数,按从小到大的顺序排列。全部的内容,包括:用VB编写程序。题如下:随便输入10个正整数,按从小到大的顺序排列。、vb 编写一个能对一维数组进行升序排列的子程序过程!、编写vb程序,随机产生10个3位数,按从大到小递减的顺序排列,并显示排等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)