VB题目:随机产生1-33之间的6个随机数(保证6个数字不重复)按照从大到小的顺序排列

在线等谢谢... 在线等谢谢 展开
 我来答
tchangyun
推荐于2016-12-02 · TA获得超过2012个赞
知道小有建树答主
回答量:1244
采纳率:0%
帮助的人:732万
展开全部
Private Sub Command1_Click()
Dim num(6) As Integer
Dim i As Integer, j As Integer
Dim tmp As Integer

Randomize '防止每次生出随机数一样
For i = 0 To 5

num(i) = Int(Rnd * 53) + 1
Next

PrintNum "新生成的6个随机数为:", num()

For i = 0 To 5
For j = 0 To 5
If num(j) < num(j + 1) Then
tmp = num(j)
num(j) = num(j + 1)
num(j + 1) = tmp
End If
Next
Next

PrintNum "排序后的6个随机数为:", num()

End Sub
'------------------------------------------------------------------------以下用于打印数组

Public Function PrintNum(str As String, num() As Integer)
Dim tmpString As String
Dim i As Integer

For i = 0 To 5
tmpString = tmpString & " " & num(i)
Next

Print str & tmpString

End Function
追问
说PRINTNUM子函数未定义?
追答

我把完整工程发上来了,你自己下载了运行就可以了,希望有帮助

匿名用户
2013-05-05
展开全部
Private Sub Command1_Click()
Dim i As Integer, j As Integer, myOutput As String
Randomize (Timer)
For i = 1 To 6
j = Int(Rnd * 33) + 1
If InStr(1, myOutput, Format(j, "00") & " ") = 0 Then
myOutput = myOutput & Format(j, "00") & " "
Else
i = i - 1
End If
Next
For i = 33 To 1 Step -1
If InStr(1, myOutput, Format(i, "00") & " ") Then Print Format(i, "00") & " ";
Next
Print
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友bdb9803
2013-05-05 · TA获得超过1.1万个赞
知道大有可为答主
回答量:1.1万
采纳率:53%
帮助的人:9965万
展开全部
Private Sub Command1_Click()
Dim a(32) As Integer, i, j, t
For i = 0 To 32
a(i) = i + 1
Next
Randomize
For i = 0 To 5
j = Int(Rnd * 33)
t = a(i)
a(i) = a(j)
a(j) = t
Next
For i = 0 To 5
For j = 0 To i
If a(i) < a(j) Then
t = a(i)
a(i) = a(j)
a(j) = t
End If
Next
Next
For i = 0 To 5
Print a(i);
Next
Print
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
chenzh98
2013-05-05 · TA获得超过393个赞
知道小有建树答主
回答量:406
采纳率:0%
帮助的人:177万
展开全部
dim vl(5) as long
'make number
vl(0)=int(1+rnd*32)
for i=1 to 5
do

flag=true
vt=int(1+rnd*32)

for j=0 to i-1
if vt=vl(j) then
flag=false
exit for
end if
next j
loop until flag
next i
'sort
for i=0 to 4
for j=i+1 to 5
if vl(j)>vl(i) then
vt=vl(i)
vl(i)=vl(j)
vl(j)=vt
end if
next j
next i
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式