vb 用inputbox函数输入3个任意整数,安从大到小顺序输出 (块if语句)
展开全部
Private Sub Form_Click()
Dim a As Single, b As Single, c As Single, z As Single
a = InputBox("输入a的值", "")
b = InputBox("输入b的值", "")
c = InputBox("输入c的值", "")
If a < b Then z = a: b = a: b = z '先把这个较小值给z,把a的值给b,然后把较小值z传递给b,保证a最后存储大的数,b存储较小数
If a < c Then z = a: c = a: c = z '同理,先把这个较小值给z,把c的值给b,然后把较小值z传递给c,保证a最后存储大的数,z存储较小数
If b < c Then z = b: b = c: c = z '再处理b和c,保证b存较大数,c存较小数
Print a; b; c '最后a,b,c就是从大到小排列
End Sub
Dim a As Single, b As Single, c As Single, z As Single
a = InputBox("输入a的值", "")
b = InputBox("输入b的值", "")
c = InputBox("输入c的值", "")
If a < b Then z = a: b = a: b = z '先把这个较小值给z,把a的值给b,然后把较小值z传递给b,保证a最后存储大的数,b存储较小数
If a < c Then z = a: c = a: c = z '同理,先把这个较小值给z,把c的值给b,然后把较小值z传递给c,保证a最后存储大的数,z存储较小数
If b < c Then z = b: b = c: c = z '再处理b和c,保证b存较大数,c存较小数
Print a; b; c '最后a,b,c就是从大到小排列
End Sub
展开全部
Dim n(2) As Long, k As Long, i As Integer
For i = 0 To 2
n(i) = Val(InputBox("请输入第" & i + 1 & "个数"))
Next
If n(1) > n(0) Then k = n(0): n(0) = n(1): n(1) = k
If n(2) > n(0) Then k = n(0): n(0) = n(2): n(2) = k
If n(2) > n(1) Then k = n(1): n(1) = n(2): n(2) = k
MsgBox "排序后的结果:" & n(0) & "," & n(1) & "," & n(2)
For i = 0 To 2
n(i) = Val(InputBox("请输入第" & i + 1 & "个数"))
Next
If n(1) > n(0) Then k = n(0): n(0) = n(1): n(1) = k
If n(2) > n(0) Then k = n(0): n(0) = n(2): n(2) = k
If n(2) > n(1) Then k = n(1): n(1) = n(2): n(2) = k
MsgBox "排序后的结果:" & n(0) & "," & n(1) & "," & n(2)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim a(3) As Integer
For i = 1 To 3
a(i) = InputBox("请输入第" & i & "个数:")
Next i
For i = 1 To 2
For j = i + 1 To 3
If a(i) < a(j) Then
r = a(i)
a(i) = a(j)
a(j) = r
End If
Next j
Next i
For i = 1 To 3
Print a(i);
Next i
End Sub
Dim a(3) As Integer
For i = 1 To 3
a(i) = InputBox("请输入第" & i & "个数:")
Next i
For i = 1 To 2
For j = i + 1 To 3
If a(i) < a(j) Then
r = a(i)
a(i) = a(j)
a(j) = r
End If
Next j
Next i
For i = 1 To 3
Print a(i);
Next i
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询