VB编写随机产生一个数组,并且将数组元素逆序存放。(一维数组)

2024-11-30 18:01:05
推荐回答(3个)
回答(1):

逆序:从大到小,还是,从小到大,还是什么?

回答(2):

Private Sub Command8_Click()
Dim b(0 To 10) As Integer, mp As Integer, i As Integer, x As Integer
Randomize
For i = 0 To 10
b(i) = Int(Rnd * (100 - 1 + 1) + 1)
Print b(i)
Next
Print
For i = 0 To UBound(b)
For x = i + 1 To UBound(b)
If b(x) > b(i) Then
mp = b(i)
b(i) = b(x)
b(x) = mp
End If
Next
Print b(i)
Next

End Sub

回答(3):

Private Sub Command1_Click()
Dim a%(80)
Open "num1.txt" For Output As #1
Randomize
a(1) = Int(Rnd * 90 + 10)
k = 1
Do While k < 80
x = Int(Rnd * 90 + 10)
f = 0
For i = 1 To k
If x = a(i) Then
f = 1
Exit For
End If
Next i
If f = 0 Then
k = k + 1
a(k) = x
End If
Loop

n = 0
For i = 1 To 80
Write #1, a(i)
Text1.Text = Text1.Text & a(i) & " "
n = n + 1
Next i
Close #1
Private Sub Command2_Click()

Open "num1.txt" For Input As #1
k = 0
n = 0
For i = 1 To 80
Input #1,a( i)

For i = 1 To n - 1
For j = i + 1 To n
If a(i) >a(j) Then
t = a(i): a(i) = a(j): a(j) = t
End If
Next j
Next i
For j = 1 To n
Text2.Text = Text2.Text & a(j) & " "
k = k + 1

Next j
Close #1

End Sub

End Sub