1)将n乘以3后加1产生一个新的数
2)对产生的新数循环执行如下操作:新数是偶数时,用新数除以2;新数是奇数时,用新数乘以3后加1
譬如,以2为初始值,则计算过程如下。2→7→22→11→34→17→52→26→13→40→20→ 10→5→16→8→4→2。数字2不能在10步之内回到初始值。
界面如图所示,回答下列问题:
Private Sub Command1_Click()
Dim n As Integer, t as Integer ,m as Integer ,s as String
t = n * 3 + 1
m = 1
s = ""
Do While
s = s + Str(t)
If t Mod 2 = 0 Then
t = t \ 2
Else
t = t * 3 + 1
End If
m = m + 1
Loop
If n = t Then
Label1.Caption = s + Str(n)
Else
Label1.Caption = "该数10步之内无法实现!"
End If
End Sub