写输出结果#include "stdio.h"int binary(int x, int a[], int n){ int low=0,high=n-l,mid; while(low<=high) { mid=(low+high)/2; if(x>a[mid]) high=mid-l; else if(x=0 && t>a[j]) { a[j+1]=a[j]; j--;} a[j+1]=t; } printf("%d\n",binary(3,a,5)); }
举一反三
- 若输入52<;CR>;,则下面程序的运行结果是。main(){int a[8]={6,12,18,42,46,52,67,73};int low=0,mid,high=7,x;printf("Input a x:");scanf("%d",&x);while(low<;=high){mid=(low+high)/2;if(x>;a[mid]) low=mid+1;else if(x<;a[mid]) high=mid-1;else break;}if(low<;=high) printf("Search Successful! The index is:%d\n",mid);else printf("Can't search!\n");}
- 代码填空【快速排序的分区函数:以第1个元素为基准元素】 int swap(int a[], int i, int j) { int temp = a[i]; a[i] = a[j]; a[j] = temp; } int partition(int a[], int p, int q) { int x = a[/i][/i]; int i = p, j; for(j = p + 1;j <= q; j++) { if(a[j]<=x) { i++; ______(1)________; } } _________(2)___________; return i; }
- 针对如下三个实现矩阵求和的不同函数:int a[N][N];int sumA( int a[N][N] ){ int i, j; int sum = 0; for ( i = 0; i < N; i++ ) for ( j = 0; j < N; j++ ) sum += a[i][j]; return sum;}int sumB( int a[N][N] ){ int i, j; int sum = 0; for ( j = 0; j < N; j++ ) for ( i = 0; i < N; i++ ) sum += a[i][j]; return sum;}int sumC( int a[N][N] ){ int i, j; int sum = 0; for ( j = 0; j < N; j+=2 ) for ( i = 0; i < N; i+=2 ) sum += ( a[i][j] + a[i+1][j] + a[i][j+1] + a[i+1][j+1] ); return sum;}当N足够大的时候,三个函数的运行时间t1、t2、t3符合下列哪种情况?()[/i][/i][/i][/i] A: t1 > t2 > t3 B: t3 > t1 > t2 C: t2 > t3 > t1 D: t3 > t2 > t1
- 下面 rotate 函数的功能是:将 n 行 n 列的矩阵a 转置#define N 4 void rotate(int a[][N]) { int i,j,t; for(i=0;i 答案: (1) j (2) a[i][j]=a[j][i] 答案解析: 难易: 中 知识点:[/i][/i]
- 写出以下程序运行结果。 #include<iomanip.h> const int N=3; int main() { int a[N][N]={{7,-5,3},{2,8,-6},{1,-4,-2}}; int b[N][N]={{3,6,-9},{2,-8,3},{5,-2,-7}}; int i,j,c[N][N]; for(j=0;j<N;i++) //计算矩阵C for(j=0;j<N;j++) c[i][j]=a[i][j]+b[i][j]; for(j=0;j<N;i++) //输出矩阵C { for(j=0;j<N;j++) cout<<setw(5)<<c[i][j]; cout<<endl; } }[/i][/i][/i][/i]