vb求一组数的最小值和最大值
OptionBase1PrivateSubf(A()AsInteger,MaxAsInteger,MinAsInteger)DimiAsIntegerMax=A(1)Mi...
Option Base 1
Private Sub f(A() As Integer, Max As Integer, Min As Integer)
Dim i As Integer
Max = A(1)
Min = A(1)
For i = 1 To UBound(A)
If Max < A(1) Then
Max = A(1)
ElseIf Min > A(1) Then
Min = A(1)
End If
Next i
End Sub
Private Sub Command1_Click()
Dim A(10) As Integer, n As Integer
Randomize
ReDim A(n)
A(n) = Int(100 * Rnd) + 0
Text1.Text = A(10)
Text2.Text = Max
Text3.Text = Min
Text1.Text = " "
Text2.Text = " "
Text3.Text = " "
End Sub
跪求高手知道哪里有错误?
那个A(10)应该是A(n),我不小心看错了,,, 展开
Private Sub f(A() As Integer, Max As Integer, Min As Integer)
Dim i As Integer
Max = A(1)
Min = A(1)
For i = 1 To UBound(A)
If Max < A(1) Then
Max = A(1)
ElseIf Min > A(1) Then
Min = A(1)
End If
Next i
End Sub
Private Sub Command1_Click()
Dim A(10) As Integer, n As Integer
Randomize
ReDim A(n)
A(n) = Int(100 * Rnd) + 0
Text1.Text = A(10)
Text2.Text = Max
Text3.Text = Min
Text1.Text = " "
Text2.Text = " "
Text3.Text = " "
End Sub
跪求高手知道哪里有错误?
那个A(10)应该是A(n),我不小心看错了,,, 展开
2个回答
展开全部
Option Base 1
Private Sub f(A() As Integer, max As Integer, min As Integer)
Dim i As Integer
max = A(1)
min = A(1)
For i = 2 To UBound(A)
If max < A(i) Then max = A(i)
If min > A(i) Then min = A(i)
Next i
End Sub
Private Sub Command1_Click()
Dim A(10) As Integer, n As Integer, max As Integer, min As Integer
Randomize
Text1.Text = ""
For n = 1 To 10
A(n) = Int(100 * Rnd)
Text1.Text = Text1.Text & A(n) & " "
Next
f A, max, min
Text2.Text = max
Text3.Text = min
End Sub
追问
大神,那个A()是不确定个数的数组,怎么做,谢谢
追答
子过程f()中的A()本身就是没确定个数的数组,你用任意数量的数组作为参数调用f均可。
展开全部
Option Base 1
Private Sub Command1_Click()
Dim A() As Integer, n As Integer, max As Integer, min As Integer
Text1.Text = " "
Text2.Text = " "
Text3.Text = " "
Randomize
For n = 1 To 10
A(n) = Int(100 * Rnd)
Text1.Text = Text1.Text & A(n) & " "
Next
call f(a(),max,min)
Text2.Text = max
Text3.Text = min
End Sub
Private Sub f(A() As Integer, max As Integer, min As Integer)
Dim i As Integer
max = A(1)
min = A(1)
For i = 2 To UBound(A)
If max < A(i) Then max = A(i)
If min > A(i) Then min = A(i)
Next i
End Sub
你那个 Text1.Text = A(n) 是什么意思 我没有太搞明白 按照要求输出
一组数的最小值和最大值就是这样子
你看那儿不明白再问吧
追问
大神,还有点搞不懂,就是A()要求存放一组数,而没说多少个,怎么做啊
追答
Option Base 1
Private Sub Command1_Click()
Dim A() As Integer, i as integer, n As Integer, max As Integer, min As Integer
Text1.Text = " "
Text2.Text = " "
Text3.Text = " "
n =val(inputbox("输入多少个数:"))
redim a(n)
Randomize
For i = 1 To n
A(i) = Int(100 * Rnd)
Text1.Text = Text1.Text & A(i) & " "
Next i
f a(), max, min
Text2.Text = max
Text3.Text = min
End Sub
Private Sub f(A() As Integer, max As Integer, min As Integer)
Dim i As Integer
max = A(1)
min = A(1)
For i = 2 To UBound(A)
If max < A(i) Then max = A(i)
If min > A(i) Then min = A(i)
Next i
End Sub
好办 那就改!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询