vb编程 用for循环向一维数组中输入10个数,找出其中的最大值和最小值,并且交换最大值
答案:2 悬赏:10 手机版
解决时间 2021-03-23 17:51
- 提问者网友:相思似海深
- 2021-03-22 20:19
vb编程 用for循环向一维数组中输入10个数,找出其中的最大值和最小值,并且交换最大值
最佳答案
- 五星知识达人网友:枭雄戏美人
- 2021-03-22 21:13
题目不是交代了要用循环,但是你没用啊,没用循环是做不了这件事的。
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
还有你没有说什么是“交换最大值”。
全部回答
- 1楼网友:低血压的长颈鹿
- 2021-03-22 22:07
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
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
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯