cls
dim i as integer,m as integer,n as integer,k as integer
m=int(inpurbox(“输入一个整数”“m=”1234)
print “原数=”m
n=0
do while(m>0)
k=m mod 10
m=m\10
n=n*10+k
loop
print “逆序数=”n
end sub
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
Private Sub Command1_Click()Dim i As Integer
Dim IntArray(10) As Integer
For i = 1 To 10
IntArray(i) = 10 + Int((90 * Rnd))
Print "随机数" & i & "=" & IntArray(i)
Next
For i = 1 To 10
IntArray(i) = Mid(IntArray(i), 2) & Mid(IntArray(i), 1, 1)
Print "反序数" & i & "=" & IntArray(i)
Next
End Sub
Print只是用来验证数据的 可以去掉
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)