展开全部
'1、在名称为Form1,标题为“数组为参数”的窗体上有两个命令按钮C1,C2,标题分别为”输入显示”,“退出”;
'2、两个文本框Text1,Text2,初始内容为空,两个标签L1,L2,标题为标题分别为“数组中的最大值”和“数组中的最小值”。
'3、在Text1和Text2中分别显示出最大值和最小值。单击C2退出程序。
Private Sub C1_Click()
Dim array1(0 To 19) As Double
Dim a As Double
Dim b As Double
For i = 0 To 19
array1(i) = Val(InputBox("输入数值"))
Next i
Call max(array1, a, b)
Text1 = a
Text2 = b
End Sub
Private Sub C2_Click()
Unload Me
End Sub
Private Sub Form_Load()
Me.Caption = "数组为参数"
Text1 = ""
Text2 = ""
L1.Caption = "数组中的最大值"
L2.Caption = "数组中的最小值"
C1.Caption = "输入显示"
C2.Caption = "退出"
End Sub
Sub max(array1, a, b)
For i = 0 To UBound(array1) - 1
For j = UBound(array1) - 1 To i Step -1
If array1(j) > array1(j + 1) Then
a = array1(j)
array1(j) = array1(j + 1)
array1(j + 1) = a
End If
Next j
Next i
a = array1(UBound(array1))
b = array1(0)
End Sub
'2、两个文本框Text1,Text2,初始内容为空,两个标签L1,L2,标题为标题分别为“数组中的最大值”和“数组中的最小值”。
'3、在Text1和Text2中分别显示出最大值和最小值。单击C2退出程序。
Private Sub C1_Click()
Dim array1(0 To 19) As Double
Dim a As Double
Dim b As Double
For i = 0 To 19
array1(i) = Val(InputBox("输入数值"))
Next i
Call max(array1, a, b)
Text1 = a
Text2 = b
End Sub
Private Sub C2_Click()
Unload Me
End Sub
Private Sub Form_Load()
Me.Caption = "数组为参数"
Text1 = ""
Text2 = ""
L1.Caption = "数组中的最大值"
L2.Caption = "数组中的最小值"
C1.Caption = "输入显示"
C2.Caption = "退出"
End Sub
Sub max(array1, a, b)
For i = 0 To UBound(array1) - 1
For j = UBound(array1) - 1 To i Step -1
If array1(j) > array1(j + 1) Then
a = array1(j)
array1(j) = array1(j + 1)
array1(j + 1) = a
End If
Next j
Next i
a = array1(UBound(array1))
b = array1(0)
End Sub
展开全部
窗体上添加两个command,然后使用以下代码:
Dim a() As Single, i As Integer, j As Integer
Private Sub Command1_Click()
ReDim a(1 To 20) As Single
Cls
For i = 1 To 20
a(i) = Val(InputBox("请输入第" & i & "个元素的值"))
Next i
End Sub
Private Sub Command2_Click()
For i = 1 To 19
For j = i + 1 To 20
If a(i) > a(j) Then
t = a(i): a(i) = a(j): a(j) = t
End If
Next
Next
Print "最小值元素:" & a(1) & vbCrLf & "最大元素:" & a(20)
End Sub
Private Sub Form_Load()
Command1.Caption = "输入数组"
Command2.Caption = "显示"
End Sub
Dim a() As Single, i As Integer, j As Integer
Private Sub Command1_Click()
ReDim a(1 To 20) As Single
Cls
For i = 1 To 20
a(i) = Val(InputBox("请输入第" & i & "个元素的值"))
Next i
End Sub
Private Sub Command2_Click()
For i = 1 To 19
For j = i + 1 To 20
If a(i) > a(j) Then
t = a(i): a(i) = a(j): a(j) = t
End If
Next
Next
Print "最小值元素:" & a(1) & vbCrLf & "最大元素:" & a(20)
End Sub
Private Sub Form_Load()
Command1.Caption = "输入数组"
Command2.Caption = "显示"
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询