将十进制正整数d转换成r(2~9)进制的字符串,下列递归函数正确的是__________。
A: Function Trans$(ByVal d%, ByVal r%) If d = 0 Then Trans = "" Else Trans = Trans(d \ r, r) & (d Mod r) End If End Function
B: Function Trans$(ByVal d%, ByVal r%) If d = 0 Then Trans = "" Else Trans = (d Mod r) & Trans(d \ r, r) End If End Function
C: Function Trans$(ByVal d%, ByVal r%) If d = 0 Then Trans = Trans(d \ r, r) & (d Mod r) Else Trans = "" End If End Function
D: Function Trans$(ByVal d%, ByVal r%) If d = 0 Then Trans = (d Mod r) & Trans(d \ r, r) Else Trans = "" End If End Function
A: Function Trans$(ByVal d%, ByVal r%) If d = 0 Then Trans = "" Else Trans = Trans(d \ r, r) & (d Mod r) End If End Function
B: Function Trans$(ByVal d%, ByVal r%) If d = 0 Then Trans = "" Else Trans = (d Mod r) & Trans(d \ r, r) End If End Function
C: Function Trans$(ByVal d%, ByVal r%) If d = 0 Then Trans = Trans(d \ r, r) & (d Mod r) Else Trans = "" End If End Function
D: Function Trans$(ByVal d%, ByVal r%) If d = 0 Then Trans = (d Mod r) & Trans(d \ r, r) Else Trans = "" End If End Function
举一反三
- 下列计算最大公约数的递归过程,正确的是___________。 A: Sub gcd(ByVal m%, ByVal n%) Dim r% r = m n If r = 0 Then gcd = n Else gcd = gcd(n, r) End If End Sub B: Sub gcd(ByVal m%, ByVal n%) Dim r% r = m Mod n If r = 0 Then gcd = n Else gcd = gcd(n, r) End If End Sub C: Function gcd%(ByVal m%, ByVal n%) Dim r% r = m n If r = 0 Then gcd = n Else gcd = gcd(n, r) End If End Function D: Function gcd%(ByVal m%, ByVal n%) Dim r% r = m Mod n If r = 0 Then gcd = n Else gcd = gcd(n, r) End If End Function
- 已知十进制正整数 m,要转换成 r 进制字符串 s,完成此功能,如下过程头(子过程或函数过程)定义,不正确的是 。 A: Sub tran(ByVal m%, ByVal r%, ByRef s$) B: Sub tran(ByVal m%, ByVal r%, ByVal s$) C: Function s$(ByVal m%, ByVal r%) D: Function s$(ByVal r%, ByVal m%)
- 已知十进制正整数 m,要转换成 r 进制字符串 s,完成此功能,如下过程头(子过程或函数过程)定义,不正确的是 。 A: Sub tran(ByVal m%, ByVal r%, ByRef s$) B: Sub tran(ByVal m%, ByVal r%, ByVal s$) C: Function s$(ByVal m%, ByVal r%) D: Function s$(ByVal r%, ByVal m%)
- 下列myDecimal函数的功能是字符串s表示的r进制数转变成十进制数。如s=“3a” , r=16,则结果是58。请在_________处填入适当的内容完善程序。 Function myDecimal(ByVal s$, ByVal r%) As Integer Dim i%, c$, n% For i = 1 To Len(s) c = Mid(s, i, 1) Select Case c Case "a" To "z" n = Asc(c) - Asc("a") + 10 Case "A" To "Z" n = Asc(c) - Asc("A") + 10 Case Else n = Val(c) End Select myDecimal = _________ Next End Function
- Function fun(ByVal num As Long) As Long Dim k As Long k = 1 num = Abs(num) Do While num k = k * (num Mod 10) num = num \ 10 Loop fun = k End Function Private Sub command1_click() Dim n As Long, r As Long n = Val(InputBox("请输入一个数:")) r = fun(n) Print r End Sub 程序运行后,单击命令按钮,输入1234,输出结果为:( )