vb中比较3数的大小的编程,要用IF语句.
2个回答
展开全部
建Command1,代码如下。
================
Option Explicit
Private Sub Command1_Click()
Dim a As Integer, b As Integer, c As Integer, t As Integer
a = Val(InputBox("a=?"))
b = Val(InputBox("b=?"孙差和庆穗))
c = Val(InputBox("c=?"))
If a > b Then t = b: b = a: a = t
If a > c Then t = c: c = a: a = t
If b > c Then t = c: c = b: b = t
Print "从小到大:"; a; b; c
End Sub
============================================
'10个数比较大小
Option Explicit
Dim a(1 To 10) As Integer
Dim i, j, x As Integer, s As String, b As Boolean
Private Sub Command1_Click()
'产生10个不重复的随机数
s = ""
Randomize
For i = 1 To 10
b = False
x = Int(Rnd * 99 + 1)
Do
For j = 1 To i - 1
If x = a(j) Then b = True: Exit For
Next j
Loop While b = True
a(i) = x
s = s & " " & Str(a(i))
Next i
Print s
End Sub
Private Sub Command2_Click()
'对则盯10分随机数按大小排序
s = "": x = 0
For i = 2 To 10
For j = 1 To i - 1
If a(i) > a(j) Then x = a(i): a(i) = a(j): a(j) = x
Next j
Next i
For i = 1 To 10
s = s & " " & Str(a(i))
Next i
Print s
End Sub
================
Option Explicit
Private Sub Command1_Click()
Dim a As Integer, b As Integer, c As Integer, t As Integer
a = Val(InputBox("a=?"))
b = Val(InputBox("b=?"孙差和庆穗))
c = Val(InputBox("c=?"))
If a > b Then t = b: b = a: a = t
If a > c Then t = c: c = a: a = t
If b > c Then t = c: c = b: b = t
Print "从小到大:"; a; b; c
End Sub
============================================
'10个数比较大小
Option Explicit
Dim a(1 To 10) As Integer
Dim i, j, x As Integer, s As String, b As Boolean
Private Sub Command1_Click()
'产生10个不重复的随机数
s = ""
Randomize
For i = 1 To 10
b = False
x = Int(Rnd * 99 + 1)
Do
For j = 1 To i - 1
If x = a(j) Then b = True: Exit For
Next j
Loop While b = True
a(i) = x
s = s & " " & Str(a(i))
Next i
Print s
End Sub
Private Sub Command2_Click()
'对则盯10分随机数按大小排序
s = "": x = 0
For i = 2 To 10
For j = 1 To i - 1
If a(i) > a(j) Then x = a(i): a(i) = a(j): a(j) = x
Next j
Next i
For i = 1 To 10
s = s & " " & Str(a(i))
Next i
Print s
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询