![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
2010春C考試試題 |
|
2010春 第二部分C語言程序設(shè)計(jì) 一、選擇題(用答題卡答題,答案依次填在21~30答題號內(nèi),共l0分) 21.C語言規(guī)定,在一個源程序中main函數(shù)的位置 _____(21)_____ 。 A.必須在最開始 B.必須在最后 C.必須在預(yù)處理命令的后面 D.可以在其他函數(shù)之前或之后 22.以下選項(xiàng)中,______(22)______ 是C語言關(guān)鍵字 A.printf B.include C.fun D.default 23.已知有聲明"int a=3,b=4,c;",則執(zhí)行語句"c=1/2*(a+b);"后,c的值為__(23)___ 。 A.0 B. 24.設(shè)指針變量占2個字節(jié)的內(nèi)存空間,若有聲明"char *p="123";int c;",則執(zhí)行語句"c=sizeof(p);"后,c的值為__(24)___ A.1 B. 25.已知有聲明"int a=3,b=4;",下列表達(dá)式中合法的是 (25) A.a+b=7 B.a=|b| C.a=b=0 D.(a++)++ 26.已知有聲明"char s[20]="Hello";",在程序運(yùn)行過程中,若要想使數(shù)組s中的內(nèi)容修改為"Good",則以下語句中能夠?qū)崿F(xiàn)此功能的是 (26) 。 A.s="Good"; B.s[ C.strcat(s,"Good"); D.strcpy(s,"Good"); 27.已知有聲明"int a[4][4]={{1,2,3,4},{5,6,7,8),{9,10,11,12},{13,14,15,16)};",若需要引用值為12的數(shù)組元素,則下列選項(xiàng)中錯誤的是( 27 ) 。 A.*(a+2)+3 B.*(*(a+2)+3) C.*(a[2]+3) D.a[2][3] 28.已知有聲明"int n;float x,y;",則執(zhí)行語句"y=n=x=3.89;"后,y的值為 ( 28 ) 。 A.3 B.3. 29.已知有聲明"int a=12,b=15,c;",則執(zhí)行表達(dá)式"c=(a||(b-=a))"后,變量b和c的值分別為( 29 ) A.3,1 B.15, 30.下列敘述中,正確的是 _____(30)______ 。 A.C語言中的文件是流式文件,因此只能順序存取文件中的數(shù)據(jù)。 B.調(diào)用fopen函數(shù)時若用"r"或"r+"模式打開一個文件,該文件必須在指定存儲位置或默認(rèn)存儲位置處存在。 C.當(dāng)對文件進(jìn)行了寫操作后,必須先關(guān)閉該文件然后再打開,才能讀到該文件中的第1個數(shù)據(jù) D.無論以何種模式打開一個已存在的文件,在進(jìn)行了寫操作后,原有文件中的全部數(shù)據(jù)必定被覆蓋 二、填空題(將答案填寫在答題紙的相應(yīng)答題號內(nèi),每個答案只占一行,共30分) ● 基本概念 1. 數(shù)學(xué)式 2. 已知有聲明"char ch='g';",則表達(dá)式ch=ch-'a'+'A'的值為字符 (2) 的編碼。 3. 在C語言系統(tǒng)中,如果一個變量能正確存儲的數(shù)據(jù)范圍為整數(shù)-32768~32767,則該變量在內(nèi)存中占_____(3)_____個字節(jié)。 ' 4. 已知有聲明"int a[3][2]={{1,2),{3,4},{5,6}},*p=a[0];",則執(zhí)行語句"printf("%d\n",*(p+4));"后的輸出結(jié)果為__(4)___ 。 5. 已知有聲明和語句"int a;scanf("a=%d",&a);",欲從鍵盤上輸入數(shù)據(jù)使a中的值為3,則正確的輸入應(yīng)是 _____(5)_____ 。 • 閱讀程序 6. 以下程序運(yùn)行時輸出到屏幕的結(jié)果為 (6) 。 #include #define MAX(A,B) A>B?2*A:2*B void main() {int a=1,b=2,c=3,d=4,t; t=MAX(a+b,c+d); printf("%d\n",t); } 7.以下程序運(yùn)行時輸出到屏幕的結(jié)果是 (7) 。 #include void main() {int a=1,b=2; a+=b; b=a-b; a-=b; printf("%d,%d\n",a,b); } 8.以下程序運(yùn)行時輸出到屏幕的結(jié)果是 (8) 。 #include void swap(int a,int b) {int t; if(a>b)t=a,a=b,b=t; } void main() {int x=13,y=11,z=12; if(x>y)swap(x,y); if(x>z)swap(x,z); if(y>z)swap(y,z); printf("%d\t%d\t%d\n",x,y,z); } 9•以下程序運(yùn)行時輸出到屏幕的結(jié)果第一行是 (9) ,第二行是 (10) ,第三行是(11) 。 #include int g(int x,int y) { return x+y; } int f(int x,int y) { {static int x=2; if(y>2) { x=x*x; y=x; } else y=x+1; } return x+y; } void main() {int a=3; printf("%d\n",g(a,2)); printf("%d\n",f(a,3)); printf("%d\n",f(a,2)); } 10.以下程序運(yùn)行時輸出到屏幕的結(jié)果是 (12) 。 #include void fun(int m,int n) {if(m>=n) printf("%d",m); else fun(m+1,n); printf("%d",m); } void main() { fun(1,2); } 11.以下程序運(yùn)行時輸出到屏幕的結(jié)果第二行是 (13) ,第四行是 (14) 。 #include #define N 6 void main() {int i,j,a[N+1][N+1]; for(i=1;i<=N;i++) {a[i][i]=1;a[i][1]=1;} for(i=3;i<=N;i++) for(j=2;j a[i][j]=a[i-1][j-1]+a[i-1][j]; for(i=1;i<=N;i++) { for(j=1;j<=i;j++) printf("M",a[i][j]); printf("\n"); } } 12.以下程序運(yùn)行時輸出到屏幕的結(jié)果第一行是 (15) ,第二行是 (16) 。 #include void fun(char *p1,char *p2); void main() {int i; char a[]="54321"; puts(a+2); fun(a,a+4); puts(a); } void fun(char *p1,char *p2) {char t; while(p1 {t=*p1;*p1=*p2;*p2=t; p1+=2,p2-=2; } } 13.以下程序運(yùn)行時輸出至到屏幕的結(jié)果第一行是(17) ,第二行是(18) 。 #include typedef struct{int x,y;}direction; int visible(direction s,direction A,direction B,direction C) {direction p1,p2; int d; p1.x=B.x-A.x; p1.y=B.y-A.y; p2.x=C.x-A.x; p2.y=C.y-A.y; d=s.x*p1.x*p2.x+s.y*p1.y*p2.y; printf("M\n",d); return d>0; } void main() {char *ss[]={"invisible","visible"}; direction s={1,1},T={1,1},A={0,0},B={2,1}; puts(ss[visible(s,T,A,B)]); } • 完善程序 14.以下程序的功能是:統(tǒng)計(jì)一個字符串中數(shù)字字符"0"到"9"各自出現(xiàn)的次數(shù),統(tǒng)計(jì)結(jié)果保存在數(shù)組 count中。例如,如果字符串為"lenterschar4543123564879ffgh",則統(tǒng)計(jì)結(jié)果為:1:2 2:1 3:2 4:3 5:2 6:1 7:1 8:1 9:1。試完善程序以達(dá)到要求的功能。 #include void fun(char *t,int count[]) { char *p=t; while( _____(19)_____ ) { if(*p>='0' && *p<='9') count[_____(20)_____]++; p++; } } void main() {char s[80]="1enterschar4543123564879ffgh";int count[10]={0},i; fun(s,count); for(i=0;i<10;i++) if(count[i]) printf("%d:%d ",i,count[i]); } 15.下列程序的功能是對a數(shù)組a[0]~a[n-1]中存儲的n個整數(shù)從小到大排序。排序算法是:第一趟通 過比較將n個整數(shù)中的最小值放在a[0]中,最大值放在a[n-1]中;第二趟通過比較將n個整數(shù)中的 次小值放在a[1]中,次大值放在a[n-2]中;......,依次類推,直到待排序序列為遞增序列。試完喜 程序以達(dá)到要求的功能。 #include #define N 7 void sort(int a[],int n) {int i,j,min,max,t; for(i=0;i<___(21)___;i++) { ______(22)______ ; for(j=i+l;j else if(a[j]>a[max])max=j; if(min!=i) {t=a[min];a[min]=a[i];a[i]=t;} if(max!=n-i-1) if(max==i) {t=a[min];a[min]=a[n-i-1];a[n-i-1]=t;} else {t=a[max];a[max]=a[n-i-1];a[n-i-1]=t;} } } void main() {int a[N]={8,4,9,3,2,1,5},i; sort(a,N); printf("sorted:\n"); for(i=0;i printf("\n"); } 16.下列程序中函數(shù)find_replace的功能是:在s1指向的字符串中查找s2指向的字符串,并用s3指向 的字符串替換在s1中找到的所有s2字符串。若sl字符串中沒有出現(xiàn)s2字符串,則不做替換并使 函數(shù)返回0,否則函數(shù)返回1。試完善程序以達(dá)到要求的功能。 #include #include int find_replace(char s1[],char s2[],char s3[]) { int i,j,k,t=0; char temp[80]; if(s1[0]=='\0'||s2[0]=='\0')return t; for(i=0;s1[i]!='\0';i++) { k=0; j=i; while(s1[j]==s2[k]&&s2[k]!='\0') { j++; ___(23)_________ ; } if(s2[k]=='\0') { strcpy(temp,&s1[j]); ___________(24)________; i=i+strlen(s3); _______(25)_________; t=1; } } return t; } void main() {char line[80]="This is a test program and a test data."; char substr1[10]="test",substr2[10]="actual"; int k; k=find_replace(line,substr1,substr2); if(______(26)_______) puts(line); else printf("not found\n"); } 17.設(shè)hl和h2分別為兩個單鏈表的頭指針,鏈表中結(jié)點(diǎn)的數(shù)據(jù)結(jié)構(gòu)為: typedef struct node {int data; struct node *next; }NODE; . sea_del函數(shù)的功能是:刪除hl指向的鏈表中首次出現(xiàn)的與h2指向的鏈表中數(shù)據(jù)完全匹配的 若干個連續(xù)結(jié)點(diǎn),函數(shù)返回hl指向鏈表的頭指針。 例如,初態(tài)下,hl指向鏈表和h2指向鏈表如下圖所示: 試完善函數(shù)sea_del以達(dá)到要求的功能。 NODE *sea_del(NODE *h1,NODE *h2) {NODE *p,*ph,*q,*s; ph=NULL;p=q=h1; s=h2; if(h1==NULL||__(22)__) return h1; while(p!=NULL&&s!=NULL) {while(q->data==s->data&&q&&s) { q=q->next; s= __(28)__; } if(s!=NULL) /*失配時,h1起始結(jié)點(diǎn)后移,h2從首結(jié)點(diǎn)開始*/ { ph=p; p=q=p->next; s=__(29)__; } else 、 if(ph==NULL) h1=q; else ph->next=q; } __(30)__ ; }
|
|