急急急!!!VB:用键盘输入3个数,求3个数按从小到大排列输出
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了急急急!!!VB:用键盘输入3个数,求3个数按从小到大排列输出相关的知识,希望对你有一定的参考价值。
参考技术A PrivateSub
Command1_Click()
Dim
a
As
Long,
b
As
Long,
c
As
Long
a
=
InputBox("请输入第1个数的值",
"提示")
b
=
InputBox("请输入第2个数的值",
"提示")
c
=
InputBox("请输入第3个数的值",
"提示")
d
=
IIf(IIf(a
>
b,
a,
b)
>
c,
IIf(a
>
b,
a,
b),
c)
x
=
IIf(IIf(a
<
b,
a,
b)
<
c,
IIf(a
<
b,
a,
b),
c)
z
=
a
+
b
+
c
-
d
-
x
Cls
a
&
"
,
"
&
b
&
"
,
"
&
c
&
"按从大到小排列为"
&
d
&
"
>
"
&
z
&
"
>
"
&
x
End
Sub 参考技术B Private
Sub
Command1_Click()
Dim
a
As
Integer,
b
As
Integer,
t
As
Integer
a
=
Val(Text1.Text)
b
=
Val(Text2.Text)
t
=
Val(Text3.Text)
If
a
>
b
Then
c
=
a:
a
=
b:
b
=
t
End
If
If
a
>
c
Then
t
=
a:
a
=
c:
c
=
t
End
If
If
b
>
c
Then
t
=
b:
b
=
c:
c
=
t
End
If
Text4.Text
=
a
Text5.Text
=
b
Text6.Text
=
c
End
Sub
和上面的都差不多
把我们两个都采纳了吧
嘎嘎 参考技术C 使用我编的过程,自己在主函数调用即可:
Sub
FromSmallToBig(ByRef
num1
As
Integer,
ByRef
num2
As
Integer,
ByRef
num3
As
Integer)
Dim
temp
As
Integer
If
(num1
>
num2)
Then
temp
=
num1
num1
=
num2
num2
=
temp
End
If
If
(num1
>
num3)
Then
temp
=
num1
num1
=
num3
num3
=
temp
End
If
If
(num2
>
num3)
Then
temp
=
num2
num2
=
num3
num3
=
temp
End
If
End
Sub 参考技术D int
a,b,c;
(将输入的数分别赋值给abc然后)
if
a>b
and
a>c
than
a
else
if
b>c
than
b
else
c
end
if
end
if
手机编辑,条件有限
个别符号没有标出
VB编程题 输入xyz三个数,按从小到大的次序显示
VB编程题 输入xyz三个数,按从小到大的次序显示
源程序如下:
1. 利用InputBoxb函数输入3个数,存放到数值型变量中,然后对其进行比较。
2. 对三个数进行排序,只能通过两两对比,一般可用三条单分支IF语句来实现。
3 .要显示多个数据,可以用“;”逐一显示,也可利用“&”字符串连接将多个变量连接显示。
解题:
先在窗体上画一个按钮,代码如下:
Private Sub Command1_Click()
Dim x!, y!, z!
x = InputBox("input x")
y = InputBox("input y")
z = InputBox("input z")
Print " 排序前:"; x; " "; y; " "; z
If x < y Then t = x: x = y: y = t
If x < z Then t = x: x = z: z = t
If y < z Then t = y: y = z: z = t
Print " 排序后:"; x; " "; y; " "; z
End Sub
运行程序效果图如下:
扩展资料:
其他实现方法:
Private Sub Command1_Click()
Dim tmp, i, j As Integer '定变量
Dim a(2) As Integer '定数组
a(0) = x
a(1) = y
a(2) = z 'xyz三个数赋值给数组,实际调试中用实际数字代替
For i = 0 To 1
For j = 1 To 2
If a(i) > a(j) Then
tmp = a(i)
a(i) = a(j)
a(j) = tmp
End If
Next j
Next i '循环由小到大排序,估计这是考点
Print a(0)
Print a(1)
出题人的本意估计是要考数组循环排序,单纯xyz 3个数字比较的话其实还有很多更简单的写法。
Private Sub Command1_Click()
Dim tmp, i, j As Integer '定变量
Dim a(2) As Integer '定数组
a(0) = x
a(1) = y
a(2) = z 'xyz三个数赋值给数组,实际调试中用实际数字代替
For i = 0 To 1
For j = 1 To 2
If a(i) > a(j) Then
tmp = a(i)
a(i) = a(j)
a(j) = tmp
End If
Next j
Next i '循环由小到大排序,估计这是考点
Print a(0)
Print a(1)
Print a(2) ,由小到大逐一打印 参考技术B #include "stdio.h" #include "stdlib.h" int main() int a[4],i,j,m; scanf("%d",&a[1]); scanf("%d",&a[2]); scanf("%d",&a[3]); for(i=1;i
以上是关于急急急!!!VB:用键盘输入3个数,求3个数按从小到大排列输出的主要内容,如果未能解决你的问题,请参考以下文章
编程 有3个整数a、b、c,由键盘输入,编程序按从小到大的顺序输出它们