求VB高手解答。谢谢啦啊,这是江苏省09秋真题。答案是1 7 36 121.跪求。

Private Sub Command1_Click() Dim N As Integer, K As Integer N = 36: K = 5 Print Trans(N, K) End Sub Private Function Trans(N As Integer, K As Integer) As String Dim R As Integer If N <> 0 Then R = N Mod K If R < 10 Then Trans = Trans(N \ K, K) & R Print N Else Trans = Trans(N \ K, K) & Chr(55 + R) End If End If End Function

给你调整一下格式,看着舒服些。
Private Sub Command1_Click()
Dim N As Integer, K As Integer
N = 36: K = 5
Print Trans(N, K)
End Sub

Private Function Trans(N As Integer, K As Integer) As String
Dim R As Integer
If N <> 0 Then
R = N Mod K
If R < 10 Then
Trans = Trans(N \ K, K) & R
Print N
Else
Trans = Trans(N \ K, K) & Chr(55 + R)
End If
End If
End Function

调用过程如下,注意有递归
print Trans(36,5)
R=36 mod 5=1
Trans=Trans(7,5) & 1
R=7 mod 5=2
Trans=Trans(1,5) & 2
R=1 mod 5=1
Trans=Trans(0,5) & 1
本次调用N=0,什么也不做,直接返回,即Trans为空
此时Trans=1(字符串操作,空&1=1)
print N(输出 1)
此时Trans="1" & 2="12"
print N(输出 7)
此时Trans="12" & 1="121"
print N(输出36)
输出121
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答
大家正在搜