VB编程题:从键盘输入三个数,要求按从小到大的顺序输出到窗体上

 我来答
艾迪康乐园
2013-10-16 · TA获得超过491个赞
知道小有建树答主
回答量:493
采纳率:0%
帮助的人:660万
展开全部
可以采取两种方法:
'方法一,不是用数组,简单灵活

Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single, tmp As Single
a = Val(InputBox("请输入第 1 个数!", , 1))
b = Val(InputBox("请输入第 2 个数!", , 2))
c = Val(InputBox("请输入第 3 个数!", , 3))
Print "从小到大分别为 ";
If a > b Then
tmp = a
a = b
b = tmp
End If
If a > c Then
tmp = c
c = b
b = a
a = tmp
ElseIf b > c Then
tmp = b
b = c
c = tmp
End If
Print a; b; c
End Sub

'方法二,使用数组,代码紧促
Private Sub Command2_Click()
Dim a(2) As Single, tmp As Single
Dim i As Integer, j As Integer
For i = 0 To 2
a(i) = Val(InputBox("请输入第 " & i & " 个数!", , i))
Next i
For i = 0 To 1
For j = i + 1 To 2
If a(i) > a(j) Then
tmp = a(i)
a(i) = a(j)
a(j) = tmp
End If
Next
Next
Print "从小到大分别为 "; a(0); a(1); a(2)
End Sub
追问
第一个方法好谢谢
追答
祝你成功!
ZHMINGEN
2013-10-15 · TA获得超过1735个赞
知道大有可为答主
回答量:3149
采纳率:68%
帮助的人:1258万
展开全部
Private Sub Command1_Click()
Dim A(1 To 3) As Single, X As Single, I As Integer, J As Integer
For I = 1 To 3
A(I) = Val(InputBox("请输入第" & I & "个数!", "第" & I & "个数:", 0))
Next I
For I = 1 To 2
For J = 1 To 3 - I
If A(J) > A(J + 1) Then
X = A(J)
A(J) = A(J + 1)
A(J + 1) = X
End If
Next J
Next I
Print "最小数=" & A(1) & ",中间数=" & A(2) & ",最大数=" & A(3)
'或添加Text1控件
'Text1.Text = "最小数=" & A(1) & ",中间数=" & A(2) & ",最大数=" & A(3)
End Sub
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式