vb中输出反序代码
展开全部
Private Sub Command1_Click()
Dim i As Integer, n As Integer
Dim a() As Integer
n = InputBox("请输入数的个数")
ReDim a(n)
For i = 1 To n
a(i) = InputBox("请输入第" & i & "个数")
Print a(i)
Next i
Sub sort(a() As Integer, n As Integer)
For i = 1 To n / 2
x = a(i)
a(i) = a(n - i + 1)
a(n - i + 1) = x
Next i
For i = 1 To n
Print a(i)
Next
End Sub
你所说的反序是从大到小,还是把数组元素顺序倒过来?上以上程序满足后者
从大到小这样
Sub sort(a() As Integer, n As Integer)
Dim i As Integer, j As Integer, temp As Integer
For i = 1 To n - 1
k = i
For j = i + 1 To n
If a(j) > a(k) Then k = j
Next j
temp = a(k): a(k) = a(i): a(i) = temp
Next i
For i = 1 To n
Print a(i)
Next
End Sub
Dim i As Integer, n As Integer
Dim a() As Integer
n = InputBox("请输入数的个数")
ReDim a(n)
For i = 1 To n
a(i) = InputBox("请输入第" & i & "个数")
Print a(i)
Next i
Sub sort(a() As Integer, n As Integer)
For i = 1 To n / 2
x = a(i)
a(i) = a(n - i + 1)
a(n - i + 1) = x
Next i
For i = 1 To n
Print a(i)
Next
End Sub
你所说的反序是从大到小,还是把数组元素顺序倒过来?上以上程序满足后者
从大到小这样
Sub sort(a() As Integer, n As Integer)
Dim i As Integer, j As Integer, temp As Integer
For i = 1 To n - 1
k = i
For j = i + 1 To n
If a(j) > a(k) Then k = j
Next j
temp = a(k): a(k) = a(i): a(i) = temp
Next i
For i = 1 To n
Print a(i)
Next
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询