C語言程序設計復習題_第1頁
C語言程序設計復習題_第2頁
C語言程序設計復習題_第3頁
C語言程序設計復習題_第4頁
C語言程序設計復習題_第5頁
已閱讀5頁,還剩10頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、一、填空題1.對下列二叉樹進行中序遍歷的結果是 dbxeayfzc 。 2.按照軟件測試的一般步驟,集成測試應在 單元 測試之后進行。3.軟件工程三要素包括方法、工具和過程,其中, 過程 支持軟件開發(fā)的各個環(huán)節(jié)的控制和管理。4.數(shù)據(jù)庫設計包括概念設計、 邏輯設計 和物理設計。5.在二維表中,元組的 分量 不能再分成更小的數(shù)據(jù)項。6.設變量a和b已正確定義并賦初值。請寫出與a-=a+b等價的賦值表達式 a=-b 。7.若整型變量a和b中的值分別為7和9,要求按以下格式輸出a和b的值:a=7b=9請完成輸出語句printf( a=%dnb=%dn ,a,b);8.以下程序的輸出結果是 1 。#in

2、clude main() int i,j,sum;for(i=3;i=1;i-) sum=0;for(j=1;j=i;j+) sum+=i*j;printf(%dn,sum);9.以下程序的輸出結果是 9911 。#include main() int j,a=1,3,5,7,9,11,13,15,*p=a+5;for(j=3;j;j-) switch(j) case 1:case 2: printf(%d,*p+); break;case 3: printf(%d,*(-p);解:和for(j = 3; j != 0; j-)是一樣的的意思。因為在c語言中的邏輯運算中,0 與 j!=0 的結

3、果都是false。循環(huán)從3開始,每次j減1,當j=0時,循環(huán)條件不滿足,因此只巡檢3次;這種寫法很不好,不推薦使用。10.以下程序的輸出結果是 3 。#include #define n 5int fun(int *s,int a,int n) int j;*s=a;j=n;while(a!=sj)j-;return j;main() int sn+1; int k;for(k=1;k=n;k+) sk=k+1;printf(%dn,fun(s,4,n);11.以下程序的輸出結果是 15 。#includeint fun(int x) static int t=0; return(t+=x);

4、main() int s,i; for(i=1;i=5;i+) s=fun(i); printf(%dn,s);12.以下程序按下面指定的數(shù)據(jù)給x數(shù)組的下三角置數(shù),并按如下形式輸出,請?zhí)羁铡?3 72 6 91 5 8 10#includemain() int x44,n=0,i,j; for(j=0;j=j; i- ) n+;xij= n ; for(i=0;i4;i+) for(j=0;j=i;j+) printf(%3d,xij); print(n);13.以下程序的功能是:通過函數(shù)func輸入字符并統(tǒng)計字符的個數(shù)。輸入時用字符作為輸入結束標志。請?zhí)羁铡?includelong func

5、( ); /* 函數(shù)說明語句 */main() long n; n=func( ); printf(n=%ldn,n);long func() long m; for(m=0;getchar()!=; m+ ); return m;答題處,請把以上各小題的答案填寫如下:1. dbxeayfzc 2. 單元 3. 過程 4. 邏輯設計 5. 分量 6. a=-b 7. a=%dnb=%dn 8. 1 9. 9911 10. 3 11. 15 12. i- 、 n 13. func( ) 、 m+ 二、填空題1測試用例包括輸入值集和 輸出 值集。 2深度為5的滿二叉樹有 16 個葉子結點。 3設某

6、循環(huán)隊列的容量為50,頭指針front=5(指向隊頭元素的前一位置),尾指針rear=29(指向隊尾元素),則該循環(huán)隊列中共有 24 個元素。 4在關系數(shù)據(jù)庫中,用來表示實體之間聯(lián)系的是 關系 。 5 在數(shù)據(jù)庫管理系統(tǒng)提供的數(shù)據(jù)定義語言、數(shù)據(jù)操縱語言和數(shù)據(jù)控制語言中, 數(shù)據(jù)定義語言 負責數(shù)據(jù)的模式定義與數(shù)據(jù)的物理存取構建。 6已有定義:char c=;int a=1,b;(此處c的初值為空格字符),執(zhí)行b=!c&a;后b的值為 0 。解析:b=(!c)&a7設變量已正確定義為整型,則表達式n=i=2,+i,i+的值為 3 。 8若有定義:int k;,以下程序段的輸出結果是 #2#4 。 fo

7、r(k=2;k6;k+,k+) printf(“#%d”,k); 9以下程序段的定義語句中,x1的初值是 2 ,程序運行后輸出的內容是 2468 。 #include main() int x=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,*p4,i; for(i=0;i4;i+) pi=&x2*i+1; printf(“%d ”,pi0); printf(“n”); 10以下程序的輸出結果是 35 。 #include void swap(int *a,int *b) int *t; t=a; a=b; b=t; main() int i=3,j=5,*p=&

8、i,*q=&j; swap(p,q); printf(“%d %dn”,*p,*q); 11以下程序的輸出結果是 4 。 #include main() int a5=2,4,6,8,10, *p; p=a; p+; printf(“%d”,*p); 12以下程序的輸出結果是 13 。 #include void fun(int x) if(x/20) fun(x/2); printf(“%d ”,x); main() fun(3); printf(“n”); 13以下程序中函數(shù)fun的功能是:統(tǒng)計person所指結構體數(shù)組中所有性別(sex)為m的記錄的個數(shù),存入變量n中,并做為函數(shù)值返回。

9、請?zhí)羁眨?#include #define n 3 typedef struct int num;char nam10; char sex; ss; int fun(ss person ) int i,n=0; for(i=0;in;i+) if( personi.sex =m ) n+; return n; main() ss wn=1,”aa”,f,2,”bb”,m,3,”cc”,m; int n; n=fun(w); printf(“n=%dn”,n); 14以下程序從名為filea.dat的文本文件中逐個讀入字符并顯示在屏幕上。請?zhí)羁眨?#include main() file *fp

10、; char ch; fp=fopen( ”filea.dat”,”r” ); ch=fgetc(fp); whlie(!feof(fp) putchar(ch); ch=fgetc(fp); putchar(n); fclose(fp); 答題處,請把以上各小題的答案填寫如下:1. 輸出 2. 16 3. 24 4. 關系 5. 數(shù)據(jù)定義語言 6. 0 7. 3 8. #2#4 9. 2 、 2468 10. 35 11. 4 12. 13 13. personi.sex 14. ”filea.dat”,”r” 三、選擇題:12345678910aabadbacec1以下程序運行后的輸出結果

11、是 a 。#include #include main( ) int * a, * bt * c;a = b = c = ( int * ) malloc( sizeof( int) ) ;* a=l;* b = 2;*c = 3;a = b;printf(“%d,%d,%dn”,*a,*b,*c);a) 3,3, 3 b)2,2, 3 c) 1,2, 3 d) 1, 1,32以下關于typedef的敘述中錯誤的是 a 。a)用typedef可以增加新類型b) typedef只是將已存在的類型用一個新的名字來代表c)用typedef可以為各種類型說明一個新名,但不能用來為變量說明一個新名d)用

12、typedef為類型說明一個新名,通常可以增加程序的可讀性3. 若有以下程序段 b 。typedef struct s int g; char h; t;以下敘述中正確的是a) 可用s定義結構體變量b) 可用t定義結構體變量c) s是struct類型的變量d) 34. 以下結構體類型說明和變量定義中正確的是 a 。a) typedef structint n;char c; rec;rec t1,t2;b)struct rec;int n;char c;rec t1,t2;c)typedef struct rec;int n=0;char c=a; t1,t2;rec t1,t2;d) str

13、uctint n;char c; rec ;5. 有以下定義和語句struct workersint num;char name20;char c;structint day;int month;int year; s;struct workers w,*pw;pw=&w;能給w中year成員賦1980的語句是 d 。a)* pw.year = 1980;b)w. year =1980;c)pw-year= 1980;d)w. s. year = 1980;6以下程序運行后的輸出結果是 b 。#include struct ord int x,y; dt2 = 1 ,2,3,4;main()s

14、truct ord * p = dt;printf( %d, +p-x);printf(%d, +p-y);a) 1, 2 b)2,3 c)3,4 d)4,17. 以下程序的運行結果是 a 。#include #include typedef struct char name9; char sex; float score2;stu;void f(stu a)stu b=“zhao”,m,85.0,90.0; int i;strcpy(,);a. sex=b.sex;for( i=0;i2;i+) a.scorei=b.scorei;main( )stu c= “qia

15、n”,f,95.0,92.0;f(c);printf( “%s,%c,%2.0f,%2.0fn”,,c.sex,c.score0,c.score1);a)qian,f,95,92 b)qian,m,85,90c)zhao,f,95,92d)zhao,m,85,90解析:結構體作為函數(shù)參數(shù)時是傳值調用。8. 以下程序的運行結果是 c 。#include #include typedef struct char name9; char sex; float score2;stu;stu f(stu a)stu b=“zhao”,m,85.0,90.0; int i;strcpy(a.n

16、ame,);a. sex=b.sex;for(i=0;i,2;i+) a.scorei=b.scorei;return a;main( )stu c=“qian”,f,95.0,92,0,d;d=f( c );printf( “%s,%c,%2.0f,%2.0fn”,,d.sex,d.score0,d.score1);a)qian, f, 95, 92 b) qian, 85, 90c)zhao, m, 85, 90 d) zhao, f, 95, 929. 以下程序運行后的輸出結果是 e 。#include struct s int n; int a20;void f

17、(struct s *p) int i,j,t;for(i=0;in-1;i+)for(j=i+1;jn-1;j+)if(p-aip-aj)t=p-ai;p-ai=p-aj;p-aj=t;main( )int i;struct s s=10,2,3,1,6,8,7,5,4,10,9;f(&s);for(i=0;is.n;i+) printf(“%d”,s.ai);a) 12345678910 b) 10987654321 c) 23168754109 d) 987612345 e)12345678109解析:數(shù)組部分元素采用冒泡排序法進行升序排序。10.有以下程序段,描述正確的是: c typ

18、edef struct nodeint data;struct node *next; *node;node p;a) p是指向struct node結構體變量的指針的指針。b) node p;語句出錯c) p是指向struct node結構體變量的指針d) p是struct node結構體變量四、程序填空題1. 用選擇法對10個整數(shù)排序。#include int main( )int i,j,min,temp,a11;printf(“enter data:n”);for (i=1 ; i=10 ; i+)printf(“a%d=”,i);scanf(“%d”, &ai );printf(“n

19、”);printf(“the orginal numbers:n”);for (i=1;i=10;i+)printf(“%5d”, ai );printf(“n”);for (i=1; i=9 ;i+)min=i;for ( j=i+1 ;jaj) min=j;temp=ai;ai= amin ;amin=temp;printf(“nthe sorted numbers:n”);for (i=1;i=10;i+)printf(“%5d”,ai);printf(“n”);return 0;四、分析題敘述下列各程序段的功能,按授課的思路給關鍵語句加注釋。#include #include #def

20、ine len sizeof(struct student)struct studentlong num;float score;struct student *next;int n;int main( )struct student student * creat( );/函數(shù)聲明struct student student *del(student *,long); /函數(shù)聲明struct student student *insert(student *,student *);/函數(shù)聲明void print(student *);/函數(shù)聲明struct student *head,*st

21、u;long del_num;printf(“input records:n”); /提示輸入head=creat( );/建立鏈表,返回頭指針print(head);/輸出全部結點printf(“ninput the deleted number:”);/提示用戶輸入要刪除的結點scanf(“%ld”,&del_num);/輸入要刪除的學號while(del_num !=0)/當輸入的學號為0時結束循環(huán)head=del(head,del_num);/刪除結點后返回鏈表的頭地址print(head);/輸出全部結點printf(“input the deleted number:”);/*提示

22、用戶輸入要刪除的結點*/scanf(“%ld”,&del_num);/輸入要刪除的學號printf(“ninput the inserted record:”);/提示輸入要插入的結點stu=(struct student *)malloc(len);/開辟一個新結點scanf(“l(fā)d,%f ”,&stu-num,&stu-score);/輸入要插入的結點while(stu-num !=0)/當要輸入的學號為零時結束循環(huán)head=insert(head,stu);/返回鏈表的頭地址,賦給headprint(head);/輸出全部結點printf(“input the inserted reco

23、rd:”);/*請用戶輸入要插入的結點*/stu=(struct student *)malloc(len);/開辟一個新結點scanf(“%ld,%f ”,&stu-num,&stu-score);/輸入插入結點的數(shù)據(jù)return 0;/建立鏈表的函數(shù)creat( )struct student * creat( )struct student * head;struct student * p1,* p2;n=0;p1=p2=(struct student *)malloc(len);scanf(“%ld,%f “,&p1-num,&p1-score);head=null;while(p1

24、-num !=0)n=n+1;if(n=1)head=p1;else p2-next=p1;p2=p1;p1=(struct student *)malloc(len);scanf(“%ld,%f “,&p1-num,&p1-score);p2-next=null;return(head);/刪除鏈表中結點的函數(shù)del(struct student * head,long num )struct student * del(struct student * head,long num)struct student * p1, * p2;if(head=null)/若是空表printf(“nli

25、st null ! n”);return(head) ;p1=head;/使p1指向第1個結點while(num !=p1-num & p1-next !=null)/p1指向的不是所要找的結點且后面還有結點p2=p1 ; p1=p1-next;/p1后移一個結點if(num=p1-num)/找到了 if(p1=head)head=p1-next;/*若p1指向的是首結點,把第2個結點地址賦予head*/else p2-next=p1-next;/否則將下一結點地址賦給前一結點地址printf(“delete:%ldn”,num);n=n-1;elseprintf(“%ld not been

26、found! n”,num);/找不到該結點return(head); /插入結點的函數(shù)insert(struct student *head,struct student *stud)struct student * insert(struct student * head,struct student * stud)struct student * p0,* p1,* p2;p1=head;/使p1指向第一個結點p0=stud;/指向要插入的結點if(head=null)/原來的鏈表是空表head=p0; p0-next=null;/使p0指向的結點作為頭結點elsewhile(p0-nu

27、m p1-num) & (p1-next !=null)p2=p1;/使p2指向剛才p1指向的結點p1=p1-next;/p1后移一個結點if(p0-num num)if(head=p1) head=p0;/插到原來第1個結點之前else p2-next=p0;/插到p2指向的結點之后p0-next=p1;elsep1-next=p0;p0-next=null;/插到最后的結點之后n=n+1;/結點數(shù)加1return(head);/輸出鏈表的函數(shù)print( )void print(struct student * head)struct student * p;printf(“nnow, t

28、here %d records are:n”,n);p=head;if(head !=null)doprintf(“%ld %5.1fn “,p-num,p-score);p=p-next;while(p !=null);答:以上5個函數(shù)組成一個程序,實現(xiàn)鏈表的建立、輸出、刪除和插入。在主函數(shù)中指定需要刪除和插入的結點。定義stu為指針變量,在需要插入時先用malloc開辟一個內在區(qū),將其起始地址賦給stu,然后輸入此結構變量中各成員的值。對不同的插入對象,stu的值是不同的,每次指向一個新的student變量。在調用insert函數(shù)時,實參為head和stu,將已有的鏈表起始地址傳給inse

29、rt函數(shù)的參形head,將新開辟的單元的地址stu傳給形參stud,返回的函數(shù)值是經(jīng)過插入之后的鏈表的頭指針(地址)。五、選擇題12345678910ccbbdcdadd1.以下程序運行的結果是 c 。#include #include int fun( int n)int *p;p=(int *)malloc(sizeof(int);*p = n;return *p;main() int a;a=fun(10);printf(%dn,a+fun(10);a) 0 b) 10 c) 20 d)出錯2. 有以下語句:typedef struct ttchar c;int a4 ; cin;則下列

30、敘述中正確的是 c 。a)可以用tt定義結構體變量 b)tt是struct類型的變量c)可以用cin定義結構體變量 d)cin是stmcttt類型的變量3.下面結構體的定義語句中,錯誤的是 b 。a) struct ord int x;int y;int z; struct ord a;b)struct ord int x;int y;int z;struct ord a;c) struct ord int x;int y;int z; a;d) struct int x;int y;int z; a;4. 設有定義struct complex int real,unreal; datal =

31、 1 ,8 ,data2;則以下賦值語句中錯誤的是 b 。a) data2 = data1 ;b) data2 = (2, 6);c) data2. real = data1. real;d) data2. real = data1. unreal;5.有以下程序#include #include struct a int a;char b10 ;doublec;struct a f( struct a t) ;main( ) struct a a = 1001,zhangda,1098.01 ;a= f( a) ;printf(%d,%s,%6.1fn,a.a,a.b,a.c);struct

32、 a f( struct a t) t.a=1002;strcpy(t.b,changrong);t.c=1202.0;return t; 程序運行后的輸出結果是 d 。a)1001 ,zhangda, 1098.0b) 1002, zhangda,1202.0c)1001,changrong,1098.0d)1002, changrong,1202.06. 以下程序運行的結果是 c 。#include struct stint x,y; data2=1,10,2,20;main( )st *p=data;printf(%d,p-y); printf(%dn,(+p)-x);a) 10,1 b)20,1 c)10,2 d)20,27. 以下程序運行后的輸出結果是 d 。#include typedef struct int b,p; a;void f(a c)/*注意:c是結構變量名*/int j;c.

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論