VB题 急求 。利用随机函数rnd产生30个10~100之间的整数,再将它们按照由小到大的顺序排列输出

2024-12-17 04:25:14
推荐回答(3个)
回答1:

前几天,我写信给别人弄的,他是一个1-100号十,命令改变,我稍微(别忘了细长形状的背后哦!短,无法显示)也增加命令

私人Command1_Click()

i随着昏暗的整数,B字符串,A(20)作为INTEGER

做,直到我= 20'开始循环添加阵列变量

我:“设置”选项卡,重复跳一个随机数

A(I)= INT(RND * 101)'分配给变量数组随机数

当j = 0到i - 1'循环检查重复
如果A(J)= A(I)然后转到我:'如果你重复跳转到“设置”选项卡,一个随机数下面j个'退出循环

B = B&“,”&A(I)

I = I + 1'数组循环加1

循环

B'输出
结束子

回答2:

Private Sub Command1_Click()
Dim a(29) As Integer, tmp As Integer
Dim i As Integer, j As Integer
Randomize Time
For i = 0 To 29
a(i) = Int(Rnd * 71) + 30
Next
For i = 0 To 29
For j = i To 29
If a(i) > a(j) Then
tmp = a(i)
a(i) = a(j)
a(j) = tmp
End If
Next
Next
For i = 0 To 29
Print a(i);
If i = 14 Then Print
Next

End Sub

回答3:

Dim Inta(0 To 29) As IntegerDim SetNo As Integer
Dim i As Integer

Randomize
For i = 0 To 29
Inta(i) = 10 + Int(Rnd * 90)
Next

For i = 0 To 29
For b = i To 29
If Inta(i) > Inta(b) Then SetNo = Inta(i): Inta(i) = Inta(b): Inta(b) = SetNo
Next
Next

For i = 0 To 29
MsgBox Inta(i)
Next