【填空题】补充完成以下函数功能,返回数组a中的第n大元素的值 int fun(int a[], int s, int n) { const int MININT = -10000; int i, j, max, index; for (i = 0; i < n; ++i) { max = MININT; for (j = i; j < s; ++j) if (a[j] > __(1)___) { max = a[j]; index = j; } a[index] = a[i]; a[i] = __(2)_____; } return max; }
举一反三
- 以下程序的运行结果是 _____ 。 #include int main() { int i=2,x=5,j=7; void fun(int i,int j); fun(j,6); printf("i=%d; j=%d; x=%d\n",i,j,x); return 0; } void fun(int i,int j) { int x=7; printf("i=%d; j=%d; x=%d\n",i,j,x); }
- 在C语言中,如要给一个较大的[img=54x22]17de83d2fb35c85.png[/img]的数组赋值,以下方式性能较好的是:() A: for ( int i = 0; i <; N; i++ ) for ( int j = N - 1; j >;= 0; j-- ) mat[i][j] = val; B: for ( int i = 0; i <; N; i++ ) for ( int j = 0; j <; N; j++ ) mat[j][i] = val; C: for ( int i = N - 1; i >;= 0; i-- ) for ( int j = N - 1; j >;= 0; j-- ) mat[j][i] = val; D: for ( int i = N - 1; i >;= 0; i-- ) for ( int j = N - 1; j >;= 0; j-- ) mat[j][i] = val;
- 以下程序的运行结果为:int fun(int n){ if(n==1) return 1; else return fun(n-1)+1;} int main(){ int i,j=0; for(i=1;i<3;i++) j += fun(i); printf("%d\n",j); return 0;}
- 输出结果为___________ main( ) { int i; for (i=1;i <= 5;i++) printf("%d ",f( i )); } f(int n) { static int j=1; j=j*n; return( j ); }
- 下列程序中sumFun()的算法时间复杂度为 ( ) 。int sumFun(int n) { int count = 0; for (int i = 1; i < n; i = i * 2) for (int j = i; j > 0; j = j - 1) count = count + i + j; return count; } A: O(n) B: O(nlogn) C: O(n^2) D: O(logn logn)