题型:综合题 题类:常考题 难易度:困难
浙江省临海市白云高级中学2017-2018学年高二上学期信息技术期中考试试卷
①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
⑴ ⑵
试题篮