输入一个三位数的整数,要求将此三位数的各位上的数字重新排列,组成一个尽可能大的三位数。例如:输入213,重新排列可得到尽可能大的三位数是321。
现要求编写VB程序(运行界面如图所示),实现如下功能:在文本框Text1中输入一个三位数整数,单击“求解”按钮Command1,在文本框Text2中显示重新组合后的最大三位数整数。某同学按此要求编写的程序如下,其中函数max(x)用于求解最大三位数整数,但加框处代码有错,请改正。
①__________________②___________________
Function max(x As Integer) As Integer
Dim a As Integer, b As Integer, c As Integer, t As Integer
a =" x" \ 100
b = (x \ 10) \ 10 ' ①
c =" x" mod 10
If a < b Then t =" a:" a =" b:" b = t
If a < c Then t =" a:" a =" c:" c = t
If b < c Then t =" c:" c =" b:" b = t
max = c* 100 + b * 10 + a ' ②
End Function
Private Sub Command1_Click()
Dim n As Integer, y As Integer
n = Val(Text1.Text)
y = max(n)
Text2.Text = Str(y)
End Sub
推荐试卷