VB程序随机数的排列
我想弄一个随机产生6个数(数字两两不能相等,如果相等可以重新生成),然后重小到大排列依次放入五个筐筐里,筐筐可用frame,也可以用label请大侠帮小生编下程序...感...
我想弄一个随机产生6个数(数字两两不能相等,如果相等可以重新生成),然后重小到大排列依次放入五个筐筐里,筐筐可用frame,也可以用label
请大侠帮小生编下程序...感激不尽(在下能编出随机的数,但是就是弄不好排列)如果弄好了另有高分相送
数字随便取可以在100以内 ,是六个筐 展开
请大侠帮小生编下程序...感激不尽(在下能编出随机的数,但是就是弄不好排列)如果弄好了另有高分相送
数字随便取可以在100以内 ,是六个筐 展开
展开全部
为什么是6个数放到5个里边呢?而且还放在frame或label里,不是很明白哈
Private Sub Command1_Click()
Dim a(0 To 5) As Integer
Cls
Randomize
For i = 0 To 5
a(i) = Int(100 * Rnd)
For j = 0 To i - 1
If a(i) = a(j) Then i = i - 1: Exit For
Next
Next
Print "生成的数为:"
For i = 0 To 5
Print a(i);
Next
For i = 1 To 5
For j = 0 To 5 - i
If a(j) > a(j + 1) Then t = a(j): a(j) = a(j + 1): a(j + 1) = t
Next
Next
Print
Print "排序之后为:"
For i = 0 To 5
Print a(i);
Next
Label1.Caption = a(0)
Label2.Caption = a(1)
Label3.Caption = a(2)
Label4.Caption = a(3)
Label5.Caption = a(4)
Label6.Caption = a(5)
End Sub
Private Sub Command1_Click()
Dim a(0 To 5) As Integer
Cls
Randomize
For i = 0 To 5
a(i) = Int(100 * Rnd)
For j = 0 To i - 1
If a(i) = a(j) Then i = i - 1: Exit For
Next
Next
Print "生成的数为:"
For i = 0 To 5
Print a(i);
Next
For i = 1 To 5
For j = 0 To 5 - i
If a(j) > a(j + 1) Then t = a(j): a(j) = a(j + 1): a(j + 1) = t
Next
Next
Print "排序之后为:"
For i = 0 To 5
Print a(i);
Next
Label1.Caption = a(0)
Label2.Caption = a(1)
Label3.Caption = a(2)
Label4.Caption = a(3)
Label5.Caption = a(4)
Label6.Caption = a(5)
End Sub
展开全部
最简单是利用listbox控件的sorted属性
为true时
按小到大排序~
用for
循环从第一项取到最后一项就是
反之亦然
为true时
按小到大排序~
用for
循环从第一项取到最后一项就是
反之亦然
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在调用rnd前面加个randomize
例如
private
sub
command1_click()
randomize
x
=
val(inputbox("输入生成随机数的位数"))
for
i
=
1
to
x
str1
=
str1
&
int(rnd
*
10)
next
i
print
str1
end
sub
例如
private
sub
command1_click()
randomize
x
=
val(inputbox("输入生成随机数的位数"))
for
i
=
1
to
x
str1
=
str1
&
int(rnd
*
10)
next
i
str1
end
sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim
A(5)
As
Integer
Private
Sub
Form_Click()
Dim
I,
J
As
Integer
Dim
Temp
As
Integer
Form1.Cls
'产生6个
随机数
Randomize
For
I
=
0
To
5
A(I)
=
Int(Rnd
*
100)
Print
A(I);
Next
I
'从小到大排列
For
I
=
0
To
4
For
J
=
I
+
1
To
5
If
A(I)
>
A(J)
Then
Temp
=
A(I)
A(I)
=
A(J)
A(J)
=
Temp
End
If
Next
J
Next
I
Print
Chr(13)
'输出
For
I
=
0
To
5
Print
A(I);
Next
I
End
Sub
A(5)
As
Integer
Private
Sub
Form_Click()
Dim
I,
J
As
Integer
Dim
Temp
As
Integer
Form1.Cls
'产生6个
随机数
Randomize
For
I
=
0
To
5
A(I)
=
Int(Rnd
*
100)
A(I);
Next
I
'从小到大排列
For
I
=
0
To
4
For
J
=
I
+
1
To
5
If
A(I)
>
A(J)
Then
Temp
=
A(I)
A(I)
=
A(J)
A(J)
=
Temp
End
If
Next
J
Next
I
Chr(13)
'输出
For
I
=
0
To
5
A(I);
Next
I
End
Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询