您好!
如果我有很多組(大概10組)亂數數字,那如何寫一個程式將最大值與最小值給拿出來,謝謝…
例如
(22,54,60,10,30,40,21,54,78,62,35)
最大值78
最小值10
2006-05-28 23:07:07 · 3 個解答 · 發問者 ? 1 in 電腦與網際網路 ➔ 程式設計
Private Sub Command1_Click() Dim A, I As Integer, Min As Integer, Max As Integer A = Array(22, 54, 60, 10, 30, 40, 21, 54, 78, 62, 35) Min = A(0): Max = A(0) For I = 1 To UBound(A) If A(I) > Max Then Max = A(I) If A(I) < Min Then Min = A(I) Next Print "最大值:"; Max Print "最小值:"; MinEnd Sub
2006-05-29 07:56:01 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋
Dim Min, Max As Integer
Dim arr(10) As Integer
arr(0) = 22
arr(1) = 54
arr(2) = 60
arr(3) = 10
arr(4) = 30
arr(5) = 40
arr(6) = 21
arr(7) = 54
arr(8) = 78
arr(9) = 62
arr(10) = 35
Array.Sort(arr)
Min = arr(0)
Max = arr(10)
MsgBox("Min=" & Min & ",Max=" & Max)
2006-05-29 12:58:22 · answer #2 · answered by 文澳寶 4 · 0⤊ 0⤋
Option Base 1
Private Sub Form_Activate()
Dim x(10)
For i = 1 To 10
x(i) = Val(InputBox("Please Enter The Numbers"))
Next i
For i = 1 To 9
For j = i To 10
If x(i) < x(j) Then t = x(i): x(i) = x(j): x(j) = temp
Next j
Next i
End Sub
2006-05-29 07:58:01 · answer #3 · answered by 天使 4 · 0⤊ 0⤋