電大C語言程序設計A歷年考題(.1.7)缺09年7月小抄參考_第1頁
電大C語言程序設計A歷年考題(.1.7)缺09年7月小抄參考_第2頁
電大C語言程序設計A歷年考題(.1.7)缺09年7月小抄參考_第3頁
電大C語言程序設計A歷年考題(.1.7)缺09年7月小抄參考_第4頁
電大C語言程序設計A歷年考題(.1.7)缺09年7月小抄參考_第5頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、第一套(2010年7月試題) 一、單選題(每小題2分,共20分) 1在每個c語言程序中都必須包含有這樣一個函數,該函數的函數名為(a)。 a. main b. main c. name d. function 2每個c語言程序文件的編譯錯誤分為(b)類。 a. 1 b. 2 c. 3 d. 4 3. 字符串a+b=12n的長度為(b)。 a. 6 b. 7 c. 8 d. 9 4. 在switch語句的每個case塊中,假定都是以break語句結束的,則此switch語句容易被改寫為(d)語句。 a. for b. while c. do d. if 5. 在下面的do-while循環(huán)語句中,

2、其循環(huán)體語句被執(zhí)行的次數為(c)。 int i=0; do i+; while(i5)的相反表達式為(x!=0 | y=5) 或:(x | y=5)。 6若x=5,y=10,則x!=y的邏輯值為_1(真,true)_。 7. 假定二維數組的定義為“int a35;”,則該數組所占存儲空間的字節(jié)數為_60_。 8. 使用“typedef char bb1050;”語句定義_bb_為含有10行50列的二維字符數組類型。 9. 字符串a:xxkfile.txt的長度為_15_。 10假定p所指對象的值為25,p+1所指對象的值為46,則*+p的值為_46_。 11. 假定一個數據對象為int*類型,

3、則指向該對象的指針類型為_int*_。 12假定一個結構類型的定義為 “struct aint a,b; a* c;”,則該類型的理論長度為_12_。 13. 假定要訪問一個結構對象x中的數據成員a,則表示方式為_x.a_。 三、寫出下列每個程序運行后的輸出結果(每小題6分,共30分) 1. #include void main() int i,j,k=0; for(i=0; i5; i+) for(j=i; j5; j+) k+; printf(%dn,k); 運行結果:15 2. #include void main() int x=20; int i=2; while(ix) if(x%

4、i=0) printf(%d ,i); x/=i; i+; 運行結果:2 5 3. #include void main() int a8=70,63,54,95,40,75,90,66; int i, s=0; for(i=0; i=70 & ai=90) s+=ai; printf(s=%dn,s); 運行結果:s=235 4. #include int wf(int x, int y) x=x+y; y+=x; return x+y; void main() int x=3, y=5; printf(%dn,wf(x,y); 運行結果: 21 5. #include int la(int

5、 *a, int n) int i,s=0; for(i=0;in;i+) s+=ai; return s; void main() int a5=1,2,3,4,5; int b=la(a,5)+la(a+1,3); printf(b=%dn,b); 運行結果: b=24 四、寫出下列每個函數的功能(每小題6分,共12分) 1. int sg(int x) /x為大于等于2的整數 int i=2; if(x=2 | x=3) return 1; while(i*i=x) if(x%i=0) break; i+; if(i*idata; f=f-next; while(f) if(f-data

6、x) x=f-data; f=f-next; return x; 假定struct intnode的結點類型定義為: struct intnode int data; struct intnode* next;函數功能:求出并返回由f所指向的單鏈表中所有結點的最大值。 五、按照題目要求編寫程序或函數(每小題6分,共12分) 1. 編寫一個主函數,計算1+3+32+.+310的值并輸出,假定分別用i,p,s作為循環(huán)變量、累乘變量和累加變量的標識符。程序為: #include void main() int i; int p=1; int s=1; for(i=1;i=10;i+) p*=3; s

7、+=p; printf(%dn,s); 2. 根據函數原型“int ff(int a, int n)”,編寫函數定義,計算并返回數組an中所有元素之和。程序為:int ff(int a, int n) int i,sum=0; for(i=0; i0 & x=10)的相反表達式為(a)。 ax10 bx10 cx=0 | x0 & x10 3當處理特定問題時的循環(huán)次數已知時,通常采用(a)循環(huán)來解決。 afor bwhile cdo-while dswitch 4假定i的初值為0,則在循環(huán)語句“while(iscore 。三、寫出下列每個程序運行后的輸出結果 1. #include void

8、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.); 運行結果:default switch end. 2. #include void main() int f1,f2,i; f1=1; printf(%d ,f1); for(i=2;i=5;i+) f2=3*f1+1; printf(%d

9、 ,f2); f1=f2; printf(n); 運行結果: 1 4 13 40 121 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); 運行結果:6 4 4. #include #include void main( ) char s15=567891234; int i, n=strlen(s) ; for(i=0; in/2; i+) char c

10、=si; si=sn-1-i; sn-1-i=c; printf(%sn,s); 運行結果:432198765 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); 運行結果: b=566. #include void main() int i, s=0; for(i=1;i+) if(s30) break; if(i%2=0) s+=i;

11、printf(s=%dn,s); 運行結果:s=42 7. #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); 運行結果:66 18 8. #include void sb(char ch) switch(ch) case a: case a: printf(ww ); break; case b: case b: printf(gg ); break; default

12、: printf(bb ); break; void main() char a1=a,a2=b,a3=f; sb(a1);sb(a2);sb(a3); printf(n); 運行結果:ww gg bb 9. #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); 運行結果:58 46 37 22 15 10 10. #include s

13、truct worker char name15; int age; float pay; ; void main() struct worker x=wanghua,52,2350; struct worker y, *p; y=x; p=&x; printf(%d %7.2fn, y.age+p-age, p-pay+20); 運行結果:104 2370.00 五、按題目要求編寫程序或函數1. 編寫一個程序,輸出50以內(含50)的、能夠被3或者5整除的所有整數。程序為:#include void main() int i; for(i=3; i=50; i+) if(i%3=0 | i%

14、5=0) printf(%d ,i); printf(n); 2. 編寫一個遞歸函數“int ff(int a, int n)”,求出數組a中所有n個元素之積并返回。程序為: int ff(int a, int n) if(ny的值為0(假)。 7. 假定二維數組的定義為“int a35;”,則該數組所含元素的個數為15 。 8. 執(zhí)行“typedef int abc10;”語句把abc定義為具有10個整型元素的_數組_類型。 9. strcat()函數用于連接兩個字符串。 10假定p所指對象的值為25,p+1所指對象的值為46,則*p+的值為 25 。 11. 若要把一個整型指針p轉換為字符

15、指針,則采用的強制轉換表達式為(char*)p 。 12. null是一個符號常量,通常作為空指針值,它對應的值為 0 。 13. 假定要動態(tài)分配一個類型為struct worker的對象,并由r指針指向這個對象,則使用的表達式為 struct worker* r =malloc(sizeof(struct worker)。三、寫出下列每個程序運行后的輸出結果(每小題6分,共30分) 1. #include void main() int i,s=0; for(i=1;i6;i+) s+=i*i; printf(“s=%dn”,s); 運行結果: s=55 2. #include #defin

16、e 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); 運行結果: 2 8 21 3. #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); 運行結果:10 4. #include

17、 void main() int a,b; for(a=2,b=3; b20;) printf(%d %d ,a,b); a=a+b; b=a+b; printf(%d %dn,a,b); 運行結果:2 3 5 8 13 21 5. #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); 運行結果:15 26 26 15五、按題目要求編寫程序或函數(每小題6分,共12分) 1. 編寫

18、一個程序,輸出50以內(含50)的、能夠被3或者5整除的所有整數。#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)”,求出數組a中所有n個元素之積并返回。 2. int ff(int a, int n) if(n=0) printf(n值非法n),exit(1); if(n=1) return an-1; else return an-1*ff(a,n-1); 第四套(2009年1月試題) 一、單選

19、題(每小題2分,共20分) 1. 由c語言目標文件連接而成的可執(zhí)行文件的缺省擴展名為(b)。 a. cpp b. exe c. obj d. c 2. 設有兩條語句為“int a=12; a+=a*a;”,則執(zhí)行結束后,a的值為(c)。 a. 12 b. 144 c. 156 d. 288 3. 帶有隨機函數調用的表達式rand()%20的值在(c)區(qū)間內。 a. 119 b. 120 c. 019 d. 020 4. for循環(huán)語句“for(i=0; in; i+=2) s;”中循環(huán)體s語句被執(zhí)行的次數為(a)。 a. (n+1)/2 b. n/2+1 c. n/2-1 d. n-1 5.

20、在下列的字符數組定義中,存在語法錯誤的是(d)。 a. char a20=abcdefg; b. char a=x+y=55.; c. char a15=1,2; d. char a10=5;. 6. 若有一個函數原型為“double *function()”,則它的返回值類型為(b)。 a. 實數型 b. 實數指針型 c. 函數指針型 d. 數組型 7. 在c語言中,所有預處理命令都是以(b)符號開頭的。(b) a. * b. # c. & d. 8. 假定整數指針p所指數據單元的值為30,p+1所指數據單元的值為40,則執(zhí)行*p+后,p所指數據單元的值為(a)。 a. 40 b. 30 c

21、. 70 d. 10 9. 若要使p指向二維整型數組a1020,則p的類型為(d)。 a. int * b. int * c. int *20 d. int(*)20 10. 表示文件結束符的符號常量為(c) a. eof b. eof c. eof d. feof二、填空題(每小題2分,共26分) 1一個函數定義由 函數頭_和函數體兩部分組成。 2. 執(zhí)行“printf(%c,f-2);”語句后得到的輸出結果為 d 。 3int類型的長度為 4 。 4. 表達式(float)25/4的值為 6.25 。 5若x=5,y=10,則x=y的邏輯值為 1(或真) 。 6. 作為語句標號使用的cas

22、e和default只能用于 switch 或開關 或分情況_語句的定義體中。 7. 在程序中執(zhí)行到 return 或返回 語句時,將結束所在函數的執(zhí)行過程,返回到調用該函數的位置。 8. 假定二維數組的定義為“char amn;”,則該數組所含元素的個數為 m*n 。 9. 存儲字符a需要占用存儲器的_1_個字節(jié)空間。 10. 用于存儲一個長度為n的字符串的字符數組的長度至少為_n+1_。 11. 假定p所指對象的值為25,p+1所指對象的值為46,則執(zhí)行表達式(*p)+后,p所指對象的值為_26_。 12. 假定p是一個指向整數對象的指針,則用 *p 表示該整數對象。 13假定一個結構類型的

23、定義為“struct bint a5; char* b;”,則該類型的理論長度為_24_。三、寫出下列每個程序運行后的輸出結果(每小題6分,共30分) 1. #include void main() int i, s1=0, s2=0; for(i=0;i10;i+) if(i%2) s1+=i; else s2+=i; printf(%d %dn,s1,s2); 運行結果: 25 20 2. #include const int m=20; void main() int i=2; while(1) if(im/2) break; if(m%i=0) printf(%d ,i); i+; p

24、rintf(n); 運行結果: 2 4 5 10 3. #include int a6=4,5,6,15,20,12; void main() int i,s1,s2; s1=s2=0; for(i=0; i6; i+) switch(ai%2) case 0: s2+=ai;break; case 1: s1+=ai;break; printf(%d %dn,s1,s2); 運行結果:20 42 4. #include void main() int a33=3,5,7,9,11,13,6,8,20; int i,*p=&a00; for(i=0;i10) printf(%d ,*p); p

25、+; printf(n); 運行結果:11 13 20 5. #include #include struct worker char name15; int age; float pay; void main() struct worker x; char *t=liouting; int d=38; float f=400; strcpy(,t); x.age=d; x.pay=f; x.age+; x.pay*=2; printf(%s %d %6.2fn,,x.age,x.pay); 運行結果: liouting 39 800.00四、寫出下列每個函數的功能(每

26、小題6分,共12分) 1. #include int sa(int a, int b) if(ab) return 1; else if(a=b) return 0; else return -1; 函數功能:比較兩個整數a和b的大小,若ab則返回1,若a=b則返回0,若adata); f=f-next; printf(n); 假定struct intnode的類型定義為: struct intnode int data; struct intnode* next;函數功能:遍歷并輸出由f所指向的單鏈表中每個結點的值。五、按題目要求編寫程序或函數(每小題6分,共12分)1. 編寫一個程序,計算

27、1+3+32+.+310的值并輸出,假定分別用i,p,s作為循環(huán)變量、累乘變量和累加變量的標識符。程序為: #include void main() int i; int p=1; int s=1; for(i=1;i=10;i+) p*=3; s+=p; printf(%dn,s); 2. 根據函數原型“int ff(int a, int n)”,編寫函數定義,計算并返回數組an中所有元素之和。程序為:int ff(int a, int n) int i,sum=0; for(i=0; in; i+) sum+=ai; return sum; winger tuivasa-sheck, wh

28、o scored two tries in the kiwis 20-18 semi-final win over england, has been passed fit after a lower-leg injury, while slater has been named at full-back but is still recovering from a knee injury aggravated against usa.both sides boast 100% records heading into the encounter but australia have not

29、conceded a try since josh charnleys effort in their first pool match against england on the opening day.aussie winger jarryd hayne is the competitions top try scorer with nine, closely followed by tuivasa-sheck with eight.but it is recently named rugby league international federation player of the y

30、ear sonny bill williams who has attracted the most interest in the tournament so far.the kiwi - with a tournament high 17 offloads - has the chance of becoming the first player to win the world cup in both rugby league and rugby union after triumphing with the all blacks in 2011.id give every award

31、back in a heartbeat just to get across the line this weekend, said williams.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 150th anniversary celebrations and will attend citys premier league match at chelsea on su

溫馨提示

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

評論

0/150

提交評論