以下程序输出的结果是( )。s = 'ABCDE'def fn(n): if len(n) == 1: return n else: return n[-1] + fn(n[:-1])print(fn(s))
A: BCDEA
B: ABCDE
C: EDCBA
D: CDEAB
A: BCDEA
B: ABCDE
C: EDCBA
D: CDEAB
举一反三
- 以下程序的输出结果是______。#include [stdio.h]int f(int a[ ],int n){ if(n>1)return a[0]+f(&a[1],n-1);else return a[0];}int main(){ int aa[3]={1,2,3},s;s=f(&aa[0],3);printf(“%d\n”,s);return 0; }
- 下列函数能够求n的阶乘n!的是 A: f = lambda n: n! B: def f(n): s=1 for i in range(n): s = s * i return s C: def f(n): s=1 for i in range(n,0,-1): s = s * i return s D: def f(n): if n == 1: return 1 else: return f(n-1)*n
- 已知一窗体中有如下函数过程和一命令按钮Command1,则单击Command1时,输出结果为。 Public Function Fn(n) If n = 0 Then Fn = 1 Else Fn = Fn(n - 1) * n End Function Private Sub Command1_Click() Print Fn(6) End Sub
- 下面哪个是正确的递归函数 A: def fun1(n): if n==1: return 1 else: return n*fun1(n-1) B: def fun2(n): if n==1: return 1 else: return n*fun2(n+1) C: def fun3(n): return n*fun3(n-1) D: def fun4(n): return n*fun4(n+1)
- 以下程序的输出结果是______ 。#include int f(int n) { if(n == 1) return 1; else return n + f(n - 1);}int main(void) { printf("%d\n", f(5)); return 0;}