输入任意八个数,从大到小的顺序排序并输出

如题所述

第1个回答  2016-06-13
Option Explicit
Sub pailie()
Dim arr(500),m
Do
m=inputbox ("输入排序数字个数,不超过500","标题")
If isnumeric(m) Then
If m<=500 and m>=2 Then
Call ctrl '输入数据
Call sq()
Exit Do
else
Msgbox"必须是2-500"
End If
Else
msgbox"必须是数字"
End If
Loop
End sub
Sub ctrl() '控制输入数据类型
Dim k,i,j,result 'k控制输入循环变量
For k= 0 To m-1
do
arr(k)=inputbox("输入数字"&k+1,"数据输入")
If isnumeric(arr(k)) Then
Exit do
Else
msgbox"请输入数字"
End If
loop
Next
For i=0 To m-1
arr(i)=CDbl(arr(i))
Next
For j=0 To m-1
result = result&" "&arr(j)
next
Msgbox result,,"排列前"
End Sub

Sub sq() '排序
Dim i,j,k,result '排序使用的循环变量
Dim temp '临时储存变量
For i=0 To m-1
For j=i+1 To m-1
If arr(i)>arr(j) then
temp=arr(i)
arr(i)=arr(j)
arr(j)=temp
End If
Next
Next
For k=0 To m-1
result = result&" "&arr(k)
next
Msgbox result,,"排列后"
Msgbox typename(arr(0))
End Sub本回答被网友采纳
相似回答