VB题.将用户输入的三个数字按照从小到大获从大到小的顺序排序,排序方式可由用户设置.程序怎么写呢
来源:学生作业帮 编辑:作业帮 分类:数学作业 时间:2024/04/27 20:25:34
VB题.将用户输入的三个数字按照从小到大获从大到小的顺序排序,排序方式可由用户设置.程序怎么写呢
2012-10-30 14:58_毛线线 | 分类:VB | 浏览19次
要对a、b、c这三个数排序(依顺序为例),先比较前两个数,使得a≤b,再比较b与c,若b≤c,则排序已完成,否则需要交换b与c的值,之后再继续比较a与交换后的b,使得a小于等于b,排序结束.
求高手帮忙写下这个程序.
2012-10-30 14:58_毛线线 | 分类:VB | 浏览19次
要对a、b、c这三个数排序(依顺序为例),先比较前两个数,使得a≤b,再比较b与c,若b≤c,则排序已完成,否则需要交换b与c的值,之后再继续比较a与交换后的b,使得a小于等于b,排序结束.
求高手帮忙写下这个程序.
这里有两种方法.第一种,直接交换,代码比较多,容易出错.第二种,把交换部分写成一个独立过程,中间调用.便于阅读,书写方便,不易出错.用户的关于从大到小和从小到大排序选择,使用Option控件()如图.Private Sub Command1_Click()
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim tmp As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
If Option1.Value = True Then
If a < b Then
tmp = a
a = b
b = tmp
End If
If c > a Then
tmp = b
b = c
c = tmp
tmp = a
a = b
b = tmp
ElseIf c > b Then
tmp = b
b = c
c = tmp
End If
Else
If a > b Then
tmp = a
a = b
b = tmp
End If
If c < a Then
tmp = b
b = c
c = tmp
tmp = a
a = b
b = tmp
ElseIf c < b Then
tmp = b
b = c
c = tmp
End If
End If
Text1.Text = CStr(a)
Text2.Text = CStr(b)
Text3.Text = CStr(c)
End SubSub swap(x, y)
Dim tmp
tmp = x
x = y
y = tmp
End SubPrivate Sub Command2_Click()
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim tmp As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
If Option1.Value = True Then
If a < b Then
End If
If c > a Then
swap b, c
swap a, b
ElseIf c > b Then
swap b, c
End If
Else
If a > b Then
swap a, b
End If
If c < a Then
swap b, c
swap a, b
ElseIf c < b Then
swap b, c
End If
End If
Text1.Text = CStr(a)
Text2.Text = CStr(b)
Text3.Text = CStr(c)
End Sub
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim tmp As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
If Option1.Value = True Then
If a < b Then
tmp = a
a = b
b = tmp
End If
If c > a Then
tmp = b
b = c
c = tmp
tmp = a
a = b
b = tmp
ElseIf c > b Then
tmp = b
b = c
c = tmp
End If
Else
If a > b Then
tmp = a
a = b
b = tmp
End If
If c < a Then
tmp = b
b = c
c = tmp
tmp = a
a = b
b = tmp
ElseIf c < b Then
tmp = b
b = c
c = tmp
End If
End If
Text1.Text = CStr(a)
Text2.Text = CStr(b)
Text3.Text = CStr(c)
End SubSub swap(x, y)
Dim tmp
tmp = x
x = y
y = tmp
End SubPrivate Sub Command2_Click()
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim tmp As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
If Option1.Value = True Then
If a < b Then
End If
If c > a Then
swap b, c
swap a, b
ElseIf c > b Then
swap b, c
End If
Else
If a > b Then
swap a, b
End If
If c < a Then
swap b, c
swap a, b
ElseIf c < b Then
swap b, c
End If
End If
Text1.Text = CStr(a)
Text2.Text = CStr(b)
Text3.Text = CStr(c)
End Sub
VB题.将用户输入的三个数字按照从小到大获从大到小的顺序排序,排序方式可由用户设置.程序怎么写呢
有4个由用户任意输入的整数a,b,c和d,要求按照从大到小的顺序输出 写出程序
java 1.编写程序,从命令行输入三个整数(整数的大小自己随意设置),从小到大排序并输出.要求在程序中
编写程序,用scanf函数输入10个整数的数列,先将整数按照从大到小的顺序进行排序,然后输入一个整数插入到
C语言中从键盘上输入三个数,将之排序后按由大到小的顺序输出
三个数从小到大排序的JAVA程序
三个数从小到大排序描述 现在要写一个程序,实现给三个数排序的功能输入 输入三个正整数 输出 给输入的三个正整数排序 样例
、编写程序,任意输入10个整数的数列,先将整数按照从大到小的顺序进行排序,然后输入一个整数插入到数列中,使数列保持从大到
C语言的一个简单程序:输入100个任意数字,按从小到大排序.
VB 输入3个不同的数,将它们从大到小排序.
编写程序,输入三个整数a,b和c,按由小至大的顺序排序输出
用C语言的指针(!)实现①输入十个数字,按从小到大的顺序排序后并输出②输入十个字符,按字典顺序排序输