在Form1中加入一个Command控件,粘贴入以下代码:
Dim i As Integer, j As Integer
Dim n As Integer, m As Integer
Dim w(9, 1) As Double
Private Sub Command1_Click()
Dim a1 As Double, a2 As Double
a1 = 0
a2 = 0
For i = 1 To 10
For j = 0 To 9 - i
If w(j, 1) > w(j + 1, 1) Then
a1 = w(j, 0)
a2 = w(j, 1)
w(j, 0) = w(j + 1, 0)
w(j, 1) = w(j + 1, 1)
w(j + 1, 0) = a1
w(j + 1, 1) = a2
End If
Next j
Next i
For i = 0 To 9
Print w(i, 0)
Next
Print "名次" & " 运动员" & " 成绩"
For i = 0 To 9
Print " " & i + 1 & " " & Format(w(i, 0), "000") & " " & w(i, 1)
Next
End Sub
Private Sub Form_Load()
For i = 0 To 9
w(i, 0) = InputBox("请输入第" & i + 1 & "运动员的编号")
w(i, 1) = InputBox("请输入第" & i + 1 & "运动员的成绩")
Next
Command1.Caption = "名次排列"
End Sub
定义两数组
对时间组从小到大排序