




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領
文檔簡介
1、專業(yè)好文檔c語言程序設計課程期末復習練習 一、單選題 1在每個c語言程序中都必須包含有這樣一個函數(shù),該函數(shù)的函數(shù)名為( )。 a. main b. main c. name d. function 2每個c語言程序文件的編譯錯誤分為( )類。 a. 1 b. 2 c. 3 d. 4 3. 字符串a(chǎn)+b=12n的長度為( )。 a. 6 b. 7 c. 8 d. 9 4. 在switch語句的每個case塊中,假定都是以break語句結(jié)束的,則此switch語句容易被改寫為( )語句。 a. for b. if c. do d. while 5. 在下面的do-while循環(huán)語句中,其循環(huán)體語句
2、被執(zhí)行的次數(shù)為( )。 int i=0; do i+; while(i10); a. 4 b. 3 c. 5 d. 10 6. 將兩個字符串連接起來組成一個字符串時,選用的函數(shù)為( )。 a. strlen() b. strcap() c. strcat() d. strcmp() 7. 若用數(shù)組名作為函數(shù)調(diào)用的實參,傳遞給形參的是( )。 a. 數(shù)組的首地址 b. 數(shù)組中第一個元素的值 c. 數(shù)組中全部元素的值 d. 數(shù)組元素的個數(shù) 8. 假定a為一個整數(shù)類型的數(shù)組名,整數(shù)類型的長度為4,則元素a4的地址比a數(shù)組的首地址大( )個字節(jié)。 a. 4 b. 8 c. 16 d. 32 9. 假定
3、s被定義為指針類型char *的變量,初始指向的字符串為hello world!,若要使變量p指向s所指向的字符串,則p應定義為( )。 a. char *p=s; b. char *p=&s; c. char *p;p=*s; d. char *p; p=&s; 10. 從一個數(shù)據(jù)文件中讀入以換行符結(jié)束的一行字符串的函數(shù)為( )。 a. gets() b. fgets() c. getc() d. fgetc() 11. 由c語言目標文件連接而成的可執(zhí)行文件的缺省擴展名為( )。 a. cpp b. exe c. obj d. c 12. 設有兩條語句為“int a=12; a+=a*a;”
4、,則執(zhí)行結(jié)束后,a的值為( )。 a. 12 b. 144 c. 156 d. 288 13. 帶有隨機函數(shù)調(diào)用的表達式rand()%20的值在( )區(qū)間內(nèi)。 a. 119 b. 120 c. 019 d. 020 14. for循環(huán)語句“for(i=0; i0 & x=10)的相反表達式為( )。a. x10 b. x10c. x=0 | x0 & x10 23. 當處理特定問題時的循環(huán)次數(shù)已知時,通常采用( )循環(huán)來解決。 a. for b. while c. do-while d. switch 24. 假定i的初值為0,則在循環(huán)語句“while(ib | b=5的相反表達式為_。 6.
5、 執(zhí)行“typedef int datatype;”語句后,在使用int定義整型變量的地方也可以使用_來定義整型變量。 7. 假定一維數(shù)組的定義為“char* a8;”,則該數(shù)組所占存儲空間的字節(jié)數(shù)為_。 8. 假定二維數(shù)組的定義為“double amn;”,則該數(shù)組的列下標的取值范圍在_之間。 9. 存儲一個空字符串需要占用_個字節(jié)。 10. strcpy函數(shù)用于把一個字符串_到另一個字符數(shù)組空間中。 11. 程序的編譯單位是一個_。 12. 假定a是一個一維數(shù)組,則ai的指針訪問方式為_。 13. 執(zhí)行int *p=malloc(sizeof(int)操作得到的一個動態(tài)分配的整型對象為_。
6、 14執(zhí)行“printf(%c,a+2);”語句后得到的輸出結(jié)果為_。 15short int類型的長度為_。 16. 用類型關鍵字表示十進制常數(shù)3.26f的類型為_。 17. 假定y=10,則表達式+y*3的值為_。 18. 邏輯表達式(x=0 & y5)的相反表達式為_。 19若x=5,y=10,則x!=y的邏輯值為_。 20. 假定二維數(shù)組的定義為“int a35;”,則該數(shù)組所占存儲空間的字節(jié)數(shù)為_。 21. 使用“typedef char bb1050;”語句定義_為含有10行50列的二維字符數(shù)組類型。 22. 字符串a(chǎn):xxk數(shù)據(jù)的長度為_。 23假定p所指對象的值為25,p+1所
7、指對象的值為46,則*+p的值為_。 24. 假定一個數(shù)據(jù)對象為int*類型,則指向該對象的指針類型為_。 25假定一個結(jié)構(gòu)類型的定義為 “struct aint a,b; a* c;”,則該類型的長度為_。 26. 假定要訪問一個結(jié)構(gòu)對象x中的數(shù)據(jù)成員a,則表示方式為_。 27. 用于輸出表達式值的標準輸出函數(shù)的函數(shù)名是_。 28每個c語言程序文件在編譯時可能出現(xiàn)有致命性錯誤,其對應的標識符為_。 29. 已知az的ascii碼為6590,當執(zhí)行“int x=c+3;”語句后x的值為_。 30. 表達式(int)14.6的值為_。 31. 假定不允許使用邏輯非操作符,則關系表達式x+y5的相
8、反表達式為_。 32. 假定x=5,則執(zhí)行“a=(x?10:20);”語句后a的值為_。 33. 假定一維數(shù)組的定義為“char* am;”,則該數(shù)組所占存儲空間的字節(jié)數(shù)為_。 34. 存儲字符串a(chǎn)需要至少占用存儲器的_個字節(jié)。 35. strlen()函數(shù)用于計算一個字符串的_。 36. 在c語言中,一個函數(shù)由函數(shù)頭和_這兩個部分組成。 37假定p所指對象的值為25,p+1所指對象的值為46,則執(zhí)行表達式*(p+)后,p所指對象的值為_。 38. 假定p是一個指向整數(shù)對象的指針,則用_表示指針變量p的地址。 39. 與結(jié)構(gòu)成員訪問表達式p-name等價的訪問表達式為_。參考解答:1. ;(或
9、分號) 2. # 3. void 4. 0x195. a=b & b!=5 6. datatype 7. 32 8. 0n-19. 1 10. 拷貝(復制) 11. 程序文件 12. *(a+i)13. *p 14. c 15. 2 16. float17. 33 18. (x!=0 | y=5) 或:(x | y=5) 19. 1 20. 60 21. bb 22. 1123. 46 24. int* 25. 12 26. x.a27. printf 28. error 29. 70 30. 1431. x+y=5 32. 10 33. 4*m 34. 235. 長度 360. 函數(shù)體 37
10、. 46 38. &p39. (*p).name 三、寫出下列每個程序運行后的輸出結(jié)果 1. #include void main() int x=5; switch(2*x-1) case 4: printf(%d ,x); break; case 7: printf(%d ,2*x); break; case 10: printf(%d ,3*x); break; default: printf(%s ,default); printf(%sn,switch end.); 2. #include void main() int f1,f2,i; f1=1; printf(%d ,f1);
11、for(i=2;i=5;i+) f2=3*f1+1; printf(%d ,f2); f1=f2; printf(n); 3. #include void main() int a10=12,39,26,41,55,63,72,40,83,95; int i, i1=0, i2=0; for(i=0;i10;i+) if(ai%2=1) i1+; else i2+; printf(%d %dn,i1,i2); 4. #include #include void main( ) char s15=567891234; int i, n=strlen(s) ; for(i=0; in/2; i+)
12、 char c=si; si=sn-1-i; sn-1-i=c; printf(%sn,s); 5. #include int lb(int *a, int n) int i,s=1; for(i=0;in;i+) s*=*a+; return s; void main() int a=1,2,3,4,2,4,5,2; int b=lb(a,4)+lb(a+3,3); printf(b=%dn,b); 6. #include void main() int i,s=0; for(i=1;i6;i+) s+=i*i; printf(“s=%dn”,s); 7. #include #define
13、n 6 void main() int i,an=2,5,8,10,15,21; for(i=0; in; i+) if(ai%5) printf(%d ,ai); printf(n); 8. #include #include void main() int i; unsigned int len; char* a5=student,worker,cadre,soldier,zzeasan123; len=strlen(a0); for(i=1; ilen) len=strlen(ai); printf(%dn,len); 9. #include void main() int a,b; f
14、or(a=2,b=3; b20;) printf(%d %d ,a,b); a=a+b; b=a+b; printf(%d %dn,a,b); 10. #include void le(int* a, int* b) int x=*a; *a=*b; *b=x; void main() int x=15, y=26; printf(%d %dn,x,y); le(&x,&y); printf(%d %dn,x,y); 11. #include void main() int i, s=0; for(i=1;i+) if(s30) break; if(i%2=0) s+=i; printf(s=
15、%dn,s); 12. #include void main() int a9=36,25,48,24,55,40,18,66,20; int i, b1, b2; b1=b2=a0; for(i=1; ib1) b1=ai; if(aib2) b2=ai; printf(%d %dn,b1,b2); 13. #include void sb(char ch) switch(ch) case a: case a: printf(ww ); break; case b: case b: printf(gg ); break; default: printf(bb ); break; void m
16、ain() char a1=a,a2=b,a3=f; sb(a1);sb(a2);sb(a3); printf(n); 14. #include #define m 6 void main() int i,x; int am=10,15,22,37,46,58; for(i=0; im/2; i+) x=ai; ai=am-1-i; am-1-i=x; for(i=0; i6; i+) printf(%d ,ai); printf(n); 15. #include struct worker char name15; int age; float pay; ; void main() stru
17、ct worker x=wanghua,52,2350; struct worker y, *p; y=x; p=&x; printf(%d %7.2fn, y.age+p-age, p-pay+20); 16. #include void main() int i,j,k=0; for(i=0; i5; i+) for(j=i; j5; j+) k+; printf(%dn,k); 17. #include void main() int x=60; int i=2, p=1; while(1) if(x%i=0) p*=i; x/=i; if(ix) i+; else break; pri
18、ntf(%dn,p); 18. #include void main() int a8=76,63,54,62,40,75,90,58; int i; for(i=0; i70) printf(%d ,ai); printf(n); 19. #include void wf(int x, int y) x=x+y; y+=x; printf(%d %dn,x,y); void main() int x=3, y=8; wf(x,y); 20. #include int la(int *a, int n) int i,s=0; for(i=0;in;i+) s+=ai; return s; vo
19、id main() int a5=3,4,6,10,20; int b=la(a,5); int c=la(a+2,3); printf(%d %dn,b,c); 參考解答: 1. default switch end. 2. 1 4 13 40 121 3. 6 4 4. 432198765 5. b=56 6. s=55 7. 2 8 21 8. 10 9. 2 3 5 8 13 21 10. 15 26 26 15 11. s=42 12. 66 18 13. ww gg bb 14. 58 46 37 22 15 10 15. 104 2370.00 16. 15 17. 30 18.
20、 76 75 90 19. 11 19 20. 43 36 四、寫出下列每個函數(shù)的功能 1. #include int sg(int x) /x為大于等于2的整數(shù) int a=(int)sqrt(x); /sqrt(x)取x的平方根 int i=2; while(i=a) if(x%i=0) break; i+; if(idata; f=f-next; while(f) if(f-datax) x=f-data; f=f-next; return x; 假定struct intnode的類型定義為: struct intnode int data; struct intnode* next;
21、3. #include int sa(int a, int b) if(ab) return 1; else if(a=b) return 0; else return -1; 4. void output(struct intnode *f) /f為單鏈表的表頭指針 if(!f) return; while(f) printf(%d ,f-data); f=f-next; printf(n); 假定struct intnode的類型定義為: struct intnode int data; struct intnode* next; 5. int sc(int a, int b, int c
22、) if(a=b & a=c) return a; if(b=a & b=c) return b; return c; 6. int* li(int n) int* a=malloc(n*sizeof(int); int i; for(i=0;in;i+) scanf(%d,a+i); return a; 7. int wc(int a, int n, int k) int i, c=0; for(i=0;i=k) c+; return c; 8. void qa(struct worker a, int n) int i; for(i=0; ib則返回1,若a=b則返回0,若ab則返回-1。
23、 4. 遍歷并輸出由f所指向的單鏈表中每個結(jié)點的值。 5. 求出a,b,c三個數(shù)中的最大值并返回。 6. 首先建立一個動態(tài)整型數(shù)組an,接著從鍵盤上輸入n個整數(shù)到an中,最后返回數(shù)組an的首地址。 7. 統(tǒng)計并返回一維整型數(shù)組an中大于等于k的值的個數(shù)。 8. 從鍵盤上為具有struct worker類型的數(shù)組an輸入n個記錄。 五、按題目要求編寫程序或函數(shù) 1. 編寫一個程序,輸出50以內(nèi)(含50)的、能夠被3或者5整除的所有整數(shù)。 2. 編寫一個遞歸函數(shù)“int ff(int a, int n)”,求出數(shù)組a中所有n個元素之積并返回。 3. 編寫一個程序,利用while循環(huán),計算并打印輸出
24、的值,其中正整數(shù)n值由鍵盤輸入。假定求和變量用sum表示,計數(shù)變量用i表示,sum、i和n均定義為全局變量,sum和i的初值分別被賦予0和1。 4. 根據(jù)函數(shù)原型“void dd(int a, int n, int mm)”編寫函數(shù)定義,利用雙重循環(huán)查找并打印輸出數(shù)組an中任何兩個元素的值等于mm值的元素值。假定ai+aj等于mm,則輸出格式為:(ai,aj)。 5. 編寫一個程序,計算1+3+32+.+310的值并輸出,假定分別用i,p,s作為循環(huán)變量、累乘變量和累加變量的標識符。 6. 根據(jù)函數(shù)原型“int ff(int a, int n)”,編寫函數(shù)定義,計算并返回數(shù)組an中所有元素之和
25、。 7. 根據(jù)函數(shù)原型“double mean(double amn,int m,int n)”,編寫函數(shù)定義,要求返回二維數(shù)組amn中所有元素的平均值。假定在計算過程中采用變量v存放累加值和最后的平均值。 8. 根據(jù)函數(shù)原型“int mm(int a,int m)”,編寫函數(shù)定義,計算并返回數(shù)組am中元素最大值和最小值之差。 參考解答: 1. #include void main() int i; for(i=3; i=50; i+) if(i%3=0 | i%5=0) printf(%d ,i); printf(n); 2. int ff(int a, int n) if(n=0) pri
26、ntf(n值非法n),exit(1); if(n=1) return an-1; else return an-1*ff(a,n-1); 3. #include int n,i=1; double sum=0; void main() scanf(%d,&n); while(i=n) sum+=(double)1/i+; printf(sum=%lfn,sum); 4. void dd(int a, int n, int mm) int i,j; for(i=0; in; i+) for(j=i+1; jn; j+) if(ai+aj=mm) printf(%d, %dn, ai,aj); 5
27、. #include void main() int i; int p=1; int s=1; for(i=1;i=10;i+) p*=3; s+=p; printf(%dn,s); 6. int ff(int a, int n) int i,sum=0; for(i=0; in; i+) sum+=ai; return sum; 7. double mean(double amn,int m,int n) int i,j; double v=0.0; for(i=0; im; i+) for(j=0; jn; j+) v+=aij; v/=m*n; return v; 注:函數(shù)體的最后兩行可
28、以合并為一條返回語句:return v/=m*n 8. int mm(int a,int m) int i,x1,x2; x1=x2=a0; for(i=1; ix1) x1=ai; if(aix2) x2=ai; return x1-x2; if we dont do that it will go on and go on. we have to stop it; we need the courage to do it.his comments came hours after fifa vice-president jeffrey webb - also in london for t
29、he fas celebrations - said he wanted to meet ivory coast international toure to discuss his complaint.cska general director roman babaev says the matter has been exaggerated by the ivorian and the british media.blatter, 77, said: it has been decided by the fifa congress that it is a nonsense for rac
30、ism to be dealt with with fines. you can always find money from somebody to pay them.it is a nonsense to have matches played without spectators because it is against the spirit of football and against the visiting team. it is all nonsense.we can do something better to fight racism and discrimination
31、.this is one of the villains we have today in our game. but it is only with harsh sanctions that racism and discrimination can be washed out of football.the (lack of) air up there watch mcayman islands-based webb, the head of fifas anti-racism taskforce, is in london for the football associations 15
32、0th anniversary celebrations and will attend citys premier league match at chelsea on sunday.i am going to be at the match tomorrow and i have asked to meet yaya toure, he told bbc sport.for me its about how he felt and i would like to speak to him first to find out what his experience was.uefa hasopened disciplinary proceedings against cskafor the racist behaviour of their fans duringcitys 2-1 win.michel platini, president of european footb
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- T-ZZB 3683-2024 水松紙卷筒料圓壓圓燙金機
- 二零二五年度房屋租賃合同(含瑜伽館)
- 2025年度肥料產(chǎn)品包裝設計及印刷合同
- 2025年度綠色生態(tài)果園轉(zhuǎn)讓協(xié)議書
- 二零二五年度智慧城市建設項目業(yè)績提成合同
- 天津市2025年度勞動合同解除經(jīng)濟補償金支付與發(fā)放合同
- 二零二五年度科研機構(gòu)與高校人才合作就業(yè)協(xié)議書范本
- 二零二五年度臨時協(xié)議書:智慧社區(qū)建設與物業(yè)管理合作
- 2025年度智能車庫租賃與智慧城市建設項目合同
- 2025年度裝配行業(yè)人才培養(yǎng)終止合同協(xié)議
- 中央2025年全國婦聯(lián)所屬在京事業(yè)單位招聘93人筆試歷年參考題庫附帶答案詳解
- 廣州2025年廣東廣州市番禺區(qū)小谷圍街道辦事處下屬事業(yè)單位招聘5人筆試歷年參考題庫附帶答案詳解
- CentOS 7系統(tǒng)配置與管理(Linux 試題庫) 習題答案 (楊海艷 第2版)
- 手機直連衛(wèi)星的可用頻率分析
- 2025年春新人教版歷史七年級下冊課件 第16課-明朝的對外關系
- 施工單位工程質(zhì)量自評報告三篇
- 《家畜環(huán)境衛(wèi)生學》課件
- 2025年碳化硅(SiC)市場分析現(xiàn)狀
- 2024年湖南高速鐵路職業(yè)技術(shù)學院高職單招數(shù)學歷年參考題庫含答案解析
- 2024年沙洲職業(yè)工學院高職單招語文歷年參考題庫含答案解析
- 2024年廣東省《輔警招聘考試必刷500題》考試題庫【學生專用】
評論
0/150
提交評論