vb 编程 用for循环向一维数组中输入N个数,N的值由输入对话框输入
找出其中的最大值和最小值,并且交换最大值和最小值在数组中的位置。输出交换前以及交换后的数组中各元素的值。求教,各位大侠帮帮忙啊用vb6.0认可的程序语言...
找出其中的最大值和最小值,并且交换最大值和最小值在数组中的位置。输出交换前以及交换后的数组中各元素的值。求教,各位大侠帮帮忙啊
用vb6.0认可的程序语言 展开
用vb6.0认可的程序语言 展开
1个回答
展开全部
Sub gmyl()
Dim s(0 To 9999), s1(), max, min
kn = 0
a:
s(kn) = InputBox("", "请输入一个数")
If s(kn) = "" Then
GoTo b
End If
kn = kn + 1
GoTo a
b:
ReDim s1(0 To kn - 1)
For i = 0 To kn - 1
s1(i) = s(i)
Next i
For i = 0 To kn - 1
MsgBox s1(i)
Next i
max = s1(0): min = s1(0)
For i = 1 To kn - 1
If max < s1(i) Then
max = s1(i)
x = i
End If
Next i
For i = 1 To kn - 1
If min > s1(i) Then
min = s1(i)
n = i
End If
Next i
s1(n) = max: s1(x) = min
MsgBox "交换后数组"
For i = 0 To kn - 1
MsgBox s1(i)
Next i
End Sub
Dim s(0 To 9999), s1(), max, min
kn = 0
a:
s(kn) = InputBox("", "请输入一个数")
If s(kn) = "" Then
GoTo b
End If
kn = kn + 1
GoTo a
b:
ReDim s1(0 To kn - 1)
For i = 0 To kn - 1
s1(i) = s(i)
Next i
For i = 0 To kn - 1
MsgBox s1(i)
Next i
max = s1(0): min = s1(0)
For i = 1 To kn - 1
If max < s1(i) Then
max = s1(i)
x = i
End If
Next i
For i = 1 To kn - 1
If min > s1(i) Then
min = s1(i)
n = i
End If
Next i
s1(n) = max: s1(x) = min
MsgBox "交换后数组"
For i = 0 To kn - 1
MsgBox s1(i)
Next i
End Sub
追问
这个程序可以在vb6.0里用吗
追答
可以
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询