举一反三
- 递归函数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)
- 下列程序段的输出结果是: var f=function(n1,n2) { if (n1>n2) return n1; else return n2; } document.write(f(4,5));
- 下列js代码用于定义函数demo,正确的是? A: function demo{ 函数体;} B: function demo( )( 函数体;) C: function demo(p)( 函数体; return 值;)
- 以下代码返回的结果为。 <?php function p(){ return 1; } if(p()){ echo"false"; }else{ echo"true"; } ?>
- 320) 若要利用if-else语句判断year是否闰年,是闰年则返回1,不是闰年则返回0。 以下选项中不能完成正确判断的程序段是 A: if(year%400==0)<br/>return 1; else if(year%100!=0) if(year%4==0) return 1; else return 0; B: if(year%400!=0)<br/>if(year%100==0) return 0; else if(year%4==0) return 1; else return 0;<br/>else return 1; C: if(year%100==0)<br/>if(year%400==0) return 1; else return 0; else if(year%4==0) return 1;<br/>else return 0; D: if(year%4!=0)<br/>return 0; else if(year%400==0) return 1; else if(year%100==0) return<br/>0; else return 1;
内容
- 0
下列正确利用表达式定义JavaScript函数的是?( ) A: x = function (a, b) {return a * b}; B: var x = function {return a * b} C: var x = function (a, b) {return a * b}; D: var x = function (a, b) {a * b}
- 1
主调函数 n=21 flag=oddeven(n) if flag=0 then output even else output odd endif 被调函数: function oddeven(x) if x mod 2 !=0 return 1 else return 0 endif endfunction 请问上述伪代码运行的结果是_____________。
- 2
下列求最大值函数代码正确的是( ) A: max(a,b) { int c; if(a>b) c=a; else c=b; return c; } B: max(int a,int b) { int c; if(a>b) c=a; else c=b; return c; } C: void max(int a,int b) { int c; if(a>b) c=a; else c=b; return c; } D: int max(int a,int b) { int c; if(a>b) c=a; else c=b; return c; }
- 3
关于数组的排序,以下说法是正确的是:( ) A: arr.sort(function(a,b){return a-b}); //这是升序排列。 B: arr.sort(function(a,b){return b-a}); //这是升序排列。 C: arr.sort(function(a,b){return a-b}); //这是降序排列。 D: arr.sort(function(a,b){return b-a}); //这是降序排列。
- 4
代码填空【使用递归实现二分查找】 int binarySearch(int a[], int key, int low, int high) { if (low > high) return -1; int mid; mid = (low + high) / 2; if (key == a[mid]) return mid; else if (key < a[mid]) return ________(1)__________; else return ________(2)______________; }