vb编程,用随机函数产生50个10~100之间的互不相同的整数存于一数组中,并以升序每行10个数显示在窗体上
2个回答
展开全部
Private Sub Command1_Click()
Dim x(90) As Integer
'高效代码,产生无重复随机数
For i = 10 To 100
x(i - 10) = i
Next
Randomize
For i = 1 To 50
j = Int(Rnd * (91 - i)) + i
t = x(i)
x(i) = x(j)
x(j) = t
Next
'排序
For i = 1 To 50
For j = 1 To i
If x(i) < x(j) Then t = x(i): x(i) = x(j): x(j) = t
Next
Next
'显示
For i = 1 To 50
Print x(i);
If i Mod 10 = 0 Then Print
Next
End Sub
Dim x(90) As Integer
'高效代码,产生无重复随机数
For i = 10 To 100
x(i - 10) = i
Next
Randomize
For i = 1 To 50
j = Int(Rnd * (91 - i)) + i
t = x(i)
x(i) = x(j)
x(j) = t
Next
'排序
For i = 1 To 50
For j = 1 To i
If x(i) < x(j) Then t = x(i): x(i) = x(j): x(j) = t
Next
Next
'显示
For i = 1 To 50
Print x(i);
If i Mod 10 = 0 Then Print
Next
End Sub
展开全部
Private Sub Command1_Click()
Dim NumA(50) As Integer, Tmp1 As Long, Tmp2 As Long
For Tmp1 = 1 To 50
NumA(Tmp1) = Rnd() * 90 + 10
Next
NumA(0) = NumA(1)
For Tmp1 = 1 To 49
For Tmp2 = Tmp1 To 50
If NumA(Tmp2) < NumA(Tmp1) Then
NumA(0) = NumA(Tmp2)
NumA(Tmp2) = NumA(Tmp1)
NumA(Tmp1) = NumA(0)
End If
Next
If Tmp1 Mod 10 = 0 Then
Print NumA(Tmp1)
Else
Print NumA(Tmp1);
End If
Next
Print NumA(50)
End Sub
Dim NumA(50) As Integer, Tmp1 As Long, Tmp2 As Long
For Tmp1 = 1 To 50
NumA(Tmp1) = Rnd() * 90 + 10
Next
NumA(0) = NumA(1)
For Tmp1 = 1 To 49
For Tmp2 = Tmp1 To 50
If NumA(Tmp2) < NumA(Tmp1) Then
NumA(0) = NumA(Tmp2)
NumA(Tmp2) = NumA(Tmp1)
NumA(Tmp1) = NumA(0)
End If
Next
If Tmp1 Mod 10 = 0 Then
Print NumA(Tmp1)
Else
Print NumA(Tmp1);
End If
Next
Print NumA(50)
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询