用VB编写一程序,产生20个0~100的随机数,并用子过程的方法按从大到小的顺序排列显示
答案:2 悬赏:0 手机版
解决时间 2021-02-13 19:12
- 提问者网友:川水往事
- 2021-02-13 06:01
用VB编写一程序,产生20个0~100的随机数,并用子过程的方法按从大到小的顺序排列显示
最佳答案
- 五星知识达人网友:廢物販賣機
- 2021-02-13 07:10
用冒泡排序方法:
Option Explicit
Option Base 1
Dim a(10) As Integer
Dim i As Integer
Dim n As Integer
Private Sub Command1_Click()
n = n + 1
If n >= 9 Then
Cls
n = 0
End If
For i = 1 To 10
a(i) = Int(Rnd * 100)
Print a(i);
Next i
Print
End Sub
Private Sub Command2_Click()
Dim j, l, t, s As Integer
n = n + 1
If n >= 9 Then
Cls
n = 0
End If
For i = 1 To 9
For j = i + 1 To 10
If a(j) < a(i) Then
t = a(j)
s = a(i)
a(i) = t
a(j) = s
End If
Next j
Next i
For l = 1 To 10
Print a(l);
Next l
Print
Print "---------------------------------------"
End Sub
Option Explicit
Option Base 1
Dim a(10) As Integer
Dim i As Integer
Dim n As Integer
Private Sub Command1_Click()
n = n + 1
If n >= 9 Then
Cls
n = 0
End If
For i = 1 To 10
a(i) = Int(Rnd * 100)
Print a(i);
Next i
End Sub
Private Sub Command2_Click()
Dim j, l, t, s As Integer
n = n + 1
If n >= 9 Then
Cls
n = 0
End If
For i = 1 To 9
For j = i + 1 To 10
If a(j) < a(i) Then
t = a(j)
s = a(i)
a(i) = t
a(j) = s
End If
Next j
Next i
For l = 1 To 10
Print a(l);
Next l
Print "---------------------------------------"
End Sub
全部回答
- 1楼网友:毛毛
- 2021-02-13 07:45
sub m() dim i%, a%(20) for i = 1 to 20 a(i) = int(rnd() * 100) next call sort_disp(a()) end sub sub sort_disp(a%()) dim i%, j% for i = 1 to ubound(a) - 1 for j = i to ubound(a) if a(i) < a(j) then a(0) = a(i): a(i) = a(j):: a(j) = a(0) next next cls for i = 1 to ubound(a) print "a(" & i & ")=" & a(i) next end sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯