【加试题】神性的数学黑洞数6174。一个任意的四位正整数(四位数字完全相同除外),将数字重新组合成一个最大的数和最小的数相减,重复这个过程,最多七步,必得6174。如取四位数5462,按以上方法作运算如下: ①6542-2456=4086 ②8640-0468=8172 ③8721-1278=7443 ④7443-3447=3996
⑤9963-3699=6264 ⑥6642-2466=4176 ⑦7641-1467=6174
编写程序实现实现上述功能。从文本框Text1中输入一个任意的数字不完全相同的四位正整数,在文本框Text2中输出掉进黑洞的步数。实现上述功能的VB代码如下,但加框处代码有错,请改正:
Private Sub Command1_Click()
Dim a(1 To 4) As Integer, c As Integer, t As Integer
Dim x As Integer, y As Integer, i As Integer, j As Integer
x = Val(Text1.Text)
c = 0
Do While x <> 6174
For i = 1 To 4 '把四位正整数x的每一位数字取出并存放到数组a中
a(i) = x Mod 10
' (1)
Next i
For i = 1 To 3
For j = i + 1 To 4
If Then ' (2)
t = a(i): a(i) = a(j): a(j) = t
End If
Next j
Next i
x = a(1) * 1000 + a(2) * 100 + a(3) * 10 + a(4)
y = a(1) + a(2) * 10 + a(3) * 100 + a(4) * 1000
x = x - y
c = c + 1
Loop
Text2.Text = Str(c)
End Sub
⑴{#blank#}1{#/blank#} ⑵{#blank#}2{#/blank#}