int sum ( int n ) {
if ( n==0 )
return 0;
else
return n+sum ( n-1 ) ;
}
在执行 sum ( 10 )的过程中,递归调用 sum 函数的次数是( 9 ) 。
[单选题]阅读下面利用递归来求n!的程序 class FactorialTest { static long Factorial(int n){ //定义Factorial()方法 if(n==1)return 1; else return n * Factorial(______); } public static void main(String a[]) { //main()方法 int n=8; System.out.println(n+"!="+Factorial(n)); } } 为保证程
[主观题]已知递归函数f(n)的功能是计算 1+2+3…n,且n>=1,应采用的代码段是_____.
[单选题]已知递归函数f(n)的功能是计算1+2+…+n,且n≥1,应采用的代码段是______。A.if n>1 then return 1 else return n+f(n-1)B.if n>1 then return 1 else return n+f(n+1)C.if n<1 then return 0 else return n+f(n-1)D.if n<1 then return 0 else return n+f(n+1)
[单选题]已知递归函数f(n)的功能是打印n,n-1,…,1,且n>=1,应采用的代码段是 (42) 。(42) A.if n>1 then f(n-1);printf("%d",n);B.if n<1 then f(n+1);printf("%d",n);C.printf("%d",n);if n>1 then f(n-1);D.printf("%d",n);if n<1 then f(n+1);
[单选题]已知递归函数f(n)的功能是打印n,n-1,…,1,且n>=1,应采用的代码段是(42)。A.if n>1 then f(n-1); printf("% d",n);B.if n<1 then f(n+1); printf("% d", n);C.printf("% d",n); if n>1 then f(n-1);D.printf("% d", n); if n<1 then f(n+1);
[单选题]( 21 ) 若有下面的函数调用 :fun(a+b, 3, max(n-1, b))则 fun 的实参个数是A. ) 3B. ) 4C. ) 5D. ) 6
[单选题]阅读下列利用递归来求 n! 的程序C.lass FactorialTest{Static long Factorial (int n) { // 定义 Factorial () 方法If (n==1)Return 1;E.lseReturn n* Factorial(_____);}Public static void main (String a[]) { // main () 方法Int n=8;System.out.println{n+ ” ! = ” +Factorial (n)};}}
[主观题]本题利用递归方法求前n个自然数的和(n=10)。
[主观题]下列给定程序中,函数fun的功能是按以下递归公式求函数值。例如:当给n输入5时,函数值为240;当给n输入3时,函数值为60。请改正程序中的错误,使它能得到正确结果。注意;不要改动main函数,不得增行或删行,也不得更改程序的结构。试题程序:include <stdio.h>/*************found****+*******/fun(int n);{int c;/*************found********+*****/if(n=1)c=15;elsec=fun(n-1)*2
[单选题]阅读下列利用递归来求n!的程序 class Factorial Test{ staticlong Factorial(intn){//定义Factorial()方法 if(n==1) retum 1; else returnn*Factorial{{_____}; } publicstaticvoidmain{Stringa[)){//main()方法 intn=8; System.out.println{n+"!="+Factorial(n)}; } } 为保证程序正确运行,在下划线处应该