vb编程 用for循环向一维数组中输入10个数,找出其中的最大值和最小值,并且交换最大值
我的代码是:Dimx(1To10),max,minAsStringx(10)=Val(InputBox("输入十个整数","输入十个整数","0"))Label4.Cap...
我的代码是:
Dim x(1 To 10), max, min As String
x(10) = Val(InputBox("输入十个整数", "输入十个整数", "0"))
Label4.Caption = x(10)
为什么每次用inputbox输出来的数,不管我输入了几个数,结果都只显示第一个输进去的数呢?
求解答。 展开
Dim x(1 To 10), max, min As String
x(10) = Val(InputBox("输入十个整数", "输入十个整数", "0"))
Label4.Caption = x(10)
为什么每次用inputbox输出来的数,不管我输入了几个数,结果都只显示第一个输进去的数呢?
求解答。 展开
2个回答
展开全部
题目不是交代了要用循环,但是你没用啊,没用循环是做不了这件事的。
Dim x(1 To 10) As Integer, max As Integer, min As Integer,i As Integer
Label1.Caption = ""
For i = 1 To 10
x(i) = Val(InputBox("输入第“ & i & "个整数", "输入整数", "0"))
If i = 1 Then max = x(1) : min = x(1)
If x(i) > max Then max = x(i)
If x(i) < min Then min = x(i)
Label4.Caption = Label4.Caption & x(i) & " "
Next i
Label4.Caption = Label4.Caption & vbCrlf & "Max=" & max & " Min=" & min
还有你没有说什么是“交换最大值”。
Dim x(1 To 10) As Integer, max As Integer, min As Integer,i As Integer
Label1.Caption = ""
For i = 1 To 10
x(i) = Val(InputBox("输入第“ & i & "个整数", "输入整数", "0"))
If i = 1 Then max = x(1) : min = x(1)
If x(i) > max Then max = x(i)
If x(i) < min Then min = x(i)
Label4.Caption = Label4.Caption & x(i) & " "
Next i
Label4.Caption = Label4.Caption & vbCrlf & "Max=" & max & " Min=" & min
还有你没有说什么是“交换最大值”。
展开全部
Private Sub Command1_Click()
Dim x(1 To 10), i, max, min, a, b, t
For i = LBound(x) To UBound(x)
x(i) = InputBox("input:", i, Int(Rnd * 100))
If i = 1 Then
max = Val(x(i)): min = max
a = i: b = a
Else
If Val(x(i)) > max Then
max = Val(x(i))
a = i
End If
If Val(x(i)) < min Then
min = Val(x(i))
b = i
End If
End If
Next
Print Join(x) & vbNewLine & "max=" & max & vbNewLine & "mim=" & min
x(a) = min: x(b) = max
Print Join(x)
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询