VB三个数排序程序
2个回答
展开全部
楼主您好!
代码如下:
Option Explicit
Private Sub Form_Load()
Dim Number(3) As Double
Dim i As Integer
Dim StrMsg As String
StrMsg = StrMsg & "您输入的三个数分别为:" & vbCrLf
For i = 1 To 3
Number(i) = Val(InputBox("请输入第3个数!这是第" & CStr(i) & "个数", "提示窗口"))
StrMsg = StrMsg & "第" & CStr(i) & "个数为:" & CStr(Number(i)) & vbCrLf
Next i
For i = 1 To 2
If Number(i) > Number(i + 1) Then
Max Number(i), Number(i + 1)
End If
Next i
For i = 1 To 2
If Number(i) > Number(i + 1) Then
Max Number(i), Number(i + 1)
End If
Next i
StrMsg = StrMsg & "排序后的三个数分别为:" & vbCrLf
For i = 1 To 3
StrMsg = StrMsg & "第" & CStr(i) & "个数为:" & CStr(Number(i)) & vbCrLf
Next i
StrMsg = StrMsg & "谢谢使用!" & vbCrLf & " 软件作者:百度网友1372355088"
MsgBox StrMsg, 64 + vbOKCancel + vbDefaultButton1, "排序结果"
End Sub
Private Function Max(X As Double, Y As Double) As Double
Dim Z As Double
If X > Y Then
Z = X
X = Y
Y = Z
End If
End Function
2014-04-16
展开全部
这题居然没人答,我简单答一下吧,把这段代码直接复制就行,这是降序排列的,如果是升序排序,请把IF语句中的小于号改成大于号:
Private Sub Form_Load()
Dim a(3) As Double, i As Integer, t As Integer
For i = 1 To 3
a(i) = InputBox("请输入第" & i & "个数")
Next i
If a(1) < a(2) Then change2num a(1), a(2)
If a(1) < a(3) Then change2num a(1), a(3)
If a(2) < a(3) Then change2num a(2), a(3)
MsgBox "排序后的输出是:" & vbCrLf & a(1) & " " & a(2) & " " & a(3)
End
End Sub
Function change2num(x As Double, y As Double)
Dim t As Double
t = x
x = y
y = t
End Function
Private Sub Form_Load()
Dim a(3) As Double, i As Integer, t As Integer
For i = 1 To 3
a(i) = InputBox("请输入第" & i & "个数")
Next i
If a(1) < a(2) Then change2num a(1), a(2)
If a(1) < a(3) Then change2num a(1), a(3)
If a(2) < a(3) Then change2num a(2), a(3)
MsgBox "排序后的输出是:" & vbCrLf & a(1) & " " & a(2) & " " & a(3)
End
End Sub
Function change2num(x As Double, y As Double)
Dim t As Double
t = x
x = y
y = t
End Function
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询