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

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

设有一个递归算法如下: 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次函数调用


参考答案

更多 “ 设有一个递归算法如下: 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次函数调用 ” 相关考题
考题 设有一个递归算法如下int fact(intn){//n 大于等于0 if(n<=0)return 1; else return n* fact(n--); }则计算fact(n)需要调用该函数的次数为(30)次。A.nB.n+1C.n+2D.n-1

考题 设有一个递归算法如下 im 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次函数调用

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

考题 8、下面函数是求阶乘的递归函数,请将程序补充完整。 long Fact(int n) { if (n < 0) return 0; if (n==1 || n==0) __________________; else ____________________; }A.第4行: return 1 第5行: return n*Fact(n-1)B.第4行: return 0 第5行: return n*Fact(n-1)C.第4行: return -1 第5行: return (n-1)*Fact(n)D.第4行: return 1 第5行: return Fact(n-1)

考题 12、下面函数是求阶乘的递归函数,请将程序补充完整。 long Fact(int n) { if (n < 0) return 0; if (n==1 || n==0) __________________; else ____________________; }A.第4行: return 1 第5行: return n*Fact(n-1)B.第4行: return 0 第5行: return n*Fact(n-1)C.第4行: return -1 第5行: return (n-1)*Fact(n)D.第4行: return 1 第5行: return Fact(n-1)

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

考题 求整数n(n>=0)阶乘的算法如下,其时间复杂度是()。 fact(int n) { if(n<=1) return; return n*fact(n-1); }A.O(logn)B.O(n)C.O(nlogn)D.O(n*n)

考题 【单选题】设有一个递归算法如下A.int fact(int n) { //n大于等于0B.if(n<=0) return 1;C.else return n*fact(n-1); }D.算fact(n)需要调用该函数的次数为()。E.n+1F.n-1G.nH.n+2

考题 下面函数是求阶乘的递归函数,请将程序补充完整。 long Fact(int n) { if (n < 0) return 0; if (n==1 || n==0) __________________; else ____________________; }A.第4行: return 1 第5行: return n*Fact(n-1)B.第4行: return 0 第5行: return n*Fact(n-1)C.第4行: return -1 第5行: return (n-1)*Fact(n)D.第4行: return 1 第5行: return Fact(n-1)