展开全部
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
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
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
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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
'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
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询