网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)

下面是一个递归程序,其功能为? long Factorial(int n){ if(1==n || n==0){ return 1; } else return n*Factorial(n-1); }

A.求1至n的累加和

B.求n的阶乘

C.求n-1的阶乘

D.函数固定结果为1


参考答案和解析
C
更多 “下面是一个递归程序,其功能为? long Factorial(int n){ if(1==n || n==0){ return 1; } else return n*Factorial(n-1); }A.求1至n的累加和B.求n的阶乘C.求n-1的阶乘D.函数固定结果为1” 相关考题
考题 有以下面程序: include using namespace std; long fib(int n) { if (n>2)return (fi 有以下面程序:include <iostream>using namespace std;long fib(int n){if (n>2)return (fib(n-1)+fib(n-2));elsereturn 2;}int main(){cout<<fib(3)<<endl;return 0;}则该程序的输出结果应该是【 】。

考题 阅读下面程序:include long fib(int n){if (n>2)return (fib(n-1) + fib(n-2));else 阅读下面程序:include <iostream.h>long fib(int n){if (n>2)return (fib(n-1) + fib(n-2));elsereturn (2);}void main(){cout<<fib(3)<<end1;}则该程序的输出结果应该是【 】。

考题 如有下程序:includeusing namespace std;long fun(int n){if(n>2)return(fun(n-1)+fu 如有下程序: #include<iostream> using namespace std; long fun(int n) { if(n>2) return(fun(n-1)+fun(n-2)); else return 2; } int main() { cout<<fun(3)<<endl; return 0; } 则该程序的输出结果应该是( )。A.2B.3C.D.5

考题 有如下程序:includeusing namespace std;long fun(int n){if(n>2)return(fun(n-1)+fu 有如下程序: #include<iostream> using namespace std; long fun(int n) { if(n>2) return(fun(n-1)+fun (n-2)); else return 2; } int main() { cout<<fun(3)<<end1; return 0; } 则该程序的输出结果应该是 ( )。A.2B.3C.4D.5

考题 阅读下面程序: include using namespace std; long fib(int n) {if(n > 2) return(fib 阅读下面程序:include<iostream>using namespace std;long fib(int n){if ( n > 2 )return (fib(n-1)+fib(n-2));elsereturn 2;}int main(){cout<<fib(3)<<end1;return 0;{则该程序的输出结果应该是【 】。

考题 阅读下列利用递归来求 n! 的程序Class FactorialTest{Static long Factorial (int n) { // 定义 Factorial () 方法If (n==1)Return 1;ElseReturn n* Factorial(_____);}Public static void main (String a[]) { // main () 方法Int n=8;System.out.println{n+ ” ! = ” +Factorial (n)};}}为保证程序正确运行,在下划线处应该填入的参数是A ) n-1B ) n-2C ) nD ) n+1

考题 阅读下面利用递归来求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)); } } 为保证程序正确运行,在下画线处应该填入的参数是A.n-1B.n-2C.nD.n+1

考题 有如下程序:includelong fib(int n){if(n>2)return(fib(n-1)+fib(n-2)); else retu 有如下程序: #include<iostream.h> long fib(int n) { if(n>2)return(fib(n-1)+fib(n-2)); else return(2);} void main( ) {cout<<fib(3);} 该程序的输出结果是A.2B.4C.6D.8

考题 有如下程序:includelong fib(int n){if(n>2)return(fib(n-1)+fib(n-2)); else return( 有如下程序: #include <stdio.h> long fib(int n) { if(n>2)return(fib(n-1)+fib(n-2)); else return(2); } main() { printf("%d\n",fib(3));} 该程序的输出结果是( )。A.2B.4C.6D.8

考题 下面是一个递归Java程序,其功能为 ( )long Factorial(int n){ if(1==n){ return 1; } else return n*Factorial(n-1);}A.求1-n的和B.求2到n的和C.求n的阶乘D.求2-n的积

考题 有以下程序includeint f(int n){if(n==1)return 1:else return f(n-1)+1;}void mai 有以下程序 #include<iostream.h> int f(int n) {if(n==1)return 1: else return f(n-1)+1;} void main() {int i,j=0; for(i=1;i<3;i++):j+=f(i); cout<<j;} 程序运行后的输出结果是( )。A.4B.3C.2D.1

考题 有如下程序 long fib(int n) { if(n>2)return(fib(n-1)-fib(n-2)); else return(1); } main() { printf("%d\n",fib(5)); }该程序的输出结果是______。A.-3B.-2C.-1D.0

考题 有以下程序includeint f(int n){if(n==1 )return 1;else return f(n-1 )+ 1;}void 有以下程序#include<iostream.h>int f(int n){if(n==1 )return 1;else return f(n-1 )+ 1;}void main() {int i,j=0;for(i=1 ;i<3;i++) j+=f(i);cout<<j<<end1;}程序运行后的输出结果是( )。A.4B.3C.2D.1

考题 有以下程序 include int f(int n) {if(n==1)return1; else return f(n-1)+1} voidm 有以下程序 #include<iostream.h> int f(int n) {if(n==1)return1; else return f(n-1)+1} voidmain() {int i,j=0; for(i=l i<3;i++)=i+=f(i); cout<<j;} 程序运行后的输出结果是( )。A.4B.3C.2D.1

考题 计算N!的递归算法如下,求解该算法的时间复杂度时,只考虑相乘操作,则算法的计算时间T(n)的递推关系式为(55);对应时间复杂度为(56)。int Factorial (int n){//计算n!if(n<=1)return 1;else return n * Factorial(n-1);}(62)A.T(n)=T(n-1)+1B.T(n)=T(n-1)C.T(n)=2T(n-1)+1D.T(n)=2T(n-1)-1

考题 下列程序的输出结果为( )。 int fun(int n){ if(n==0)return 1; else return n*fun(n-1): return 0; } void main() { eout<<func(4)<<endl;}A.1B.10C.24D.11

考题 能保证对所有的参数能够结束的递归函数是A.int f(int n){if(n<1)return 1;else return n*f(n+1);}B.int f(int n){if(n>1)return 1;else return n*f(n-1);}C.int f(int n){if(abs(n)<1)return 1;else return n*f(n/2);}D.int f(int n){if(n>1)return 1;else return n*f(n*2);)

考题 阅读下列利用递归来求n!的程序。 class FactorialTest{ static long Factorial(int n){//定义Factorial方法 if(n= =1) return l; else return n*Factorial{ }; } public static void main{String a[]}{ //main方法 int n=8: System.out.println{n+"!="+Factorial (n)}; } } 为保证程序正确运行,在下画线处应该填入的参数是( )。A.n-1B.n-2C.nD.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)

考题 设有一个递归算法如下: int fact(int n){ if(n<=0)return 1; else return n*fact(n-1); } 下面正确的叙述是(35)。A.计算fact(n)需要执行n次函数调用B.计算fact(n)需要执行n+1次函数调用C.计算fact(n)需要执行n+2次函数调用D.计算fact(n)需要执行n-1次函数调用

考题 下面 ______ 是正确的递归函数,它保证对所有的参数能够结束。A.int f(int n){ if(n<1) return 1; else return n*f(n+1); }B.int f(int n){ if(n>1) return 1; else return n*f(n-1); }C.int f(int n){ if(abs(n)<1) return 1; else return n*f(n/2); }D.int f(int n){ if(n>1) return 1; else return n*f(n*2); }

考题 下列函数中,哪项是正确的递归函数( )。A int Fun(int n){if(n<1) return 1;else return n*Fun(n+1);}B) int Fun(ira n){if(abs(n)<1) return 1;else return n*Fun(n/2);}C) int Fun(int n){if(n>1) return 1;else return n*Fun(n*2)1}D) int Fun(int n){if(n>1) return 1;else retun n*Fun(n-1);}A.AB.BC.CD.D

考题 阅读下列利用递归来求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)}; } } 为保证程序正确运行,在下划线处应该填入的参数是( )。A.n-1B.n-2C.nD.n+1

考题 有以下程序 include int f(iht n) { if(n==1) return 1; else return f(n-1)+ 有以下程序 #include<iostream.h> int f(iht n) { if(n==1) return 1; else return f(n-1)+1;} void main( ) { iht i,j=0; for(i=1;i<3;i++)j+=f(i); cout < < j;} 程序运行后的输出结果是A.4B.3C.2D.1

考题 递归函数f(n)的功能是计算1+2+…+n,且n≥1,则f(n)的代码段是(49)。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)

考题 有以下程序 include using namespace std; long fib(int n) { if(n>2) return(fib(n-1 有以下程序include<iostream>using namespace std;long fib(int n){if(n>2)return(fib(n-1)+fib(n-2));elsereturn 2;}int main( ){cout<<fib(3)<<endl;return 0;}则该程序的输出结果应该是______。

考题 设有一个递归算法如下: int fact(int n) {  //n大于等于0               if(n=0) return 1;               else return n*fact(n-1);        }  则计算fact(n)需要调用该函数的次数为()A、 n+1B、 n-1C、 nD、 n+2

考题 单选题设有一个递归算法如下: int fact(int n) {  //n大于等于0               if(n=0) return 1;               else return n*fact(n-1);        }  则计算fact(n)需要调用该函数的次数为()A  n+1B  n-1C  nD  n+2