我试着不使用函数来求中值但我不知道我做错了什么。
Dim i As Integer
Dim passNum As Integer
Dim temp As Integer
Dim aantal As Integer
Dim n(1 To 50) As Single
Dim p As Integer
Dim j As Single
Dim t As Single
Dim median As Single
aantal = InputBox("how many n variables do you want max 50")
For p = 1 To aantal
n(p) = InputBox("geef " & aantal & " nummers")
Next
'Rem bubble sort names
For passNum = 1 To aantal - 1
For i = 1 To aantal - passNum
If n(i) < n(i + 1) Then
temp = n(i)
n(i) = n(i + 1)
n(i + 1) = temp
End If
Next i
Next passNum
'Rem display alphabetized list
For i = 1 To aantal
Worksheets(1).Cells(i, 1) = n(i)
Next i
'find the median
t = aantal Mod 2
If t > 0 Then
median = n(aantal + 1) / 2
Else
median = (n(aantal / 2) + (n(aatnal) / 2) + 1) / 2
End If
Worksheets(1).Cells(1, 2) = median
End Sub
这是我现在的代码,但是它找不到中间值,其他的一切都很好。
我试过把n(aantal)换成别的东西,但也不管用,要么给我错误的数字,要么什么都没有。
1条答案
按热度按时间wxclj1h51#
也许可以试试这个: