中央電大C語言程序設(shè)計模擬試題及解答參考_第1頁
中央電大C語言程序設(shè)計模擬試題及解答參考_第2頁
中央電大C語言程序設(shè)計模擬試題及解答參考_第3頁
已閱讀5頁,還剩7頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、2012 春電大 C語言程序設(shè)計模擬試題及解答、選擇題1. 由 C語言源程序文件編譯而成的目標(biāo)文件的缺省擴(kuò)展名為 ( C ) 。A. cpp B. exe C. obj D. C2. C 語言程序的基本模塊為( D )。A. 表達(dá)式 B. 標(biāo)識符 C. 語句 D. 函數(shù)3. 設(shè) x 和 y 均為邏輯值 , 則 x|y 為假的條件是 ( C ) 。A 它們均為真 B. 其中一個為真 C. 它們均為假 D. 其中一個為假4. x>0 | y=5 的相反表達(dá)式為( B )。A. x<=0 | y!=5B. x<=0 && y!=5C. x>0 | y!=5D.

2、 x>0 && y=55. 枚舉類型中的每個枚舉常量的值都是一個( A )。A. 整數(shù) B. 浮點數(shù) C. 字符 D. 邏輯值6. 循環(huán)體至少被執(zhí)行一次的語句為 ( C ) 循環(huán)語句。A for B.while C.do-while D. 任一種7. 循環(huán)語句“ for(int i=0; i<n; i+) S;”中循環(huán)體 S被執(zhí)行的次數(shù)為 ( C ) 。A. 1 B. n-1 C. n D. n+18. 在下面的 while 循環(huán)語句中,其循環(huán)體被執(zhí)行的次數(shù)為( C )。 int i=0,s=0; while(s<20) i+; s+=i;A. 4 B. 5

3、C. 6 D. 7 9在下面的字符數(shù)組定義中, ( D ) 語句有語法錯誤。A char a20= “abcdefg ”; B char a= “x+y=55. ”;C. char a15= 1', 2' ; D. char a10= '5 ';10. 若定義了函數(shù) double *function(), 則返回值類型為( B )。A.實數(shù)型 B. 實數(shù)指針型C. 函數(shù)指針型 D.數(shù)組型11. 若用數(shù)組名作為函數(shù)調(diào)用的實參,傳遞給形參的是( A )。A.數(shù)組的首地址 B.數(shù)組中第一個元素的值C.數(shù)組中全部元素的值 D.數(shù)組元素的個數(shù)12. 預(yù)處理命令在程序中都是

4、以 ( B ) 符號開頭的。A.* B.# C.& D.13. 假定 a 為一個整型數(shù)組名,則元素 a4 的地址比該數(shù)組的首地址大 ( C ) 個字節(jié)。A. 4 B. 8 C. 16 D. 3214. 下列給字符數(shù)組賦初值時,正確的是( A )。A. char s1="abcdef"B. char s24="abcd"C. char s323="abc","xyz" D. char s44='a','x','s','t'15. 變量已定義為 c

5、har *s= Heoll world! ;,要使變量指向所指向的同一個 字符串,則應(yīng)定義為( A )。A. char *p=s; B. char *p=&s; C. char *p;p=*s; D. char *p; p=&s;16. 要使 p指向二維整型數(shù)組 a1020 ,p應(yīng)定義為( D )。A. int *p=a; B. int *p=a; C. int *p20=a; D. int(*p)20=a;17. 標(biāo)準(zhǔn)輸入設(shè)備的文件流標(biāo)識符是( A )。A. stdin B. stdout C. stderr D. stdio當(dāng)文件不存在時返回打開失敗信息,則選用18. 若要

6、以讀 / 寫操作方式打開一個二進(jìn)制文件, 的打開方式字符串為( C )。A. "r+"B. "ab+" C. "rb+" D. "wb+"、填空題1. 單行或多行注釋的開始標(biāo)記符為 /* 。2. C 語言程序中所有預(yù)處理命令均以 # 字符開頭。3. 使用 #include 命令可以包含一個頭文件,也可以包含一個 程序 文件。4. 用于從鍵盤上變?yōu)樽兞枯斎胫档脴?biāo)準(zhǔn)輸入函數(shù)是 sanf() 。5. 執(zhí)行“ printf("%s%s%d","wei","rong"

7、;,18); ”語句后得到的輸出結(jié)果為 weirong18 。6. 十進(jìn)制數(shù) 25 表示成符合 C 語言規(guī)則的八進(jìn)制數(shù)為 031 。 7執(zhí)行“ printf("%c",'A'+2);”語句后得到的輸出結(jié)果為 C 。8. 假定一個枚舉類型的定義為“ enum RAab,ac,ad,ae ;” , 則 ac 值為 1 。9 short 類型的大小為 2 個字節(jié)。10. double 類型的大小為 8 個字節(jié)。11. 十進(jìn)制數(shù) 3.26f 的類型為 float 。12. 執(zhí)行“ int=45,y=13 ; printf( “%d”,x/y) ;”語句序列后得到的輸

8、出結(jié)果為 3 。13. 假定 y=10,則表達(dá)式 +y*3 的值為 33 。14. 表達(dá)式 x=x+y 表示成復(fù)合賦值表達(dá)式為 x+y=y 。15. 關(guān)系表達(dá)式 (x=0) 的等價表達(dá)式為 (!x) 。16. 假定不允許使用邏輯非操作符 , 則邏輯表達(dá)式 x>3 && x<10 的相反表達(dá)式為 x<=3 | x>=10 。17 若 x=5, y=10 ,則 x!=y 的邏輯值為 1 。18. 假定 x=5 ,則執(zhí)行“ int a=(! X? 10:20);”語句后 a 的值為 20 。19. 在 if 語句中,每個 else 關(guān)鍵字與它前面同層次并且最接

9、近的 if 關(guān)鍵字相配套。20. 若 while 循環(huán)的“頭”為“ while ( i+<=10 )” , 并且 i 的初值為 0,同時在循環(huán)體中不會 修改 i 的值,則循環(huán)體將被重復(fù)執(zhí)行 11 次后正常結(jié)束。21. 當(dāng)在程序中執(zhí)行到 contioue 語句時,將結(jié)束所在循環(huán)語句中循環(huán)體的一次執(zhí)行。22. 假定二維數(shù)組的定義為“ char a35; ”,則該數(shù)組所含元素的個數(shù)為 15 。23 假定二維數(shù)組的定義為“ char aMN; ” , 則該數(shù)組所占存儲空間的字節(jié)數(shù)為M*N 。24. 執(zhí)行“ typedef int ABC10 ;”語句把 ABC定義為具有 10 個整形元素的 數(shù)組

10、 類型。25. 存儲字符串“ a ”需要占用存儲器的 2 個字節(jié)空間。26. 字符串“ ' 'xy=4n ”的長度為 8 。27. strlen 函數(shù)用于計算一個字符串的 長度 。28. strcat 函數(shù)用于把一個字符串 連接 到另一個字符串之后的存儲空間中。29 函數(shù)中的形參變量的初值由調(diào)用該函數(shù)時對應(yīng)的 實參 值決定。30. 對于無返回值函數(shù),定義函數(shù)時要用保留字 void 修飾函數(shù)類型。31. 程序的編譯是以 程序文件 為單位進(jìn)行的。32. 假定 p 所指向?qū)ο蟮闹禐?25 , p+1 所指對象的值為 46,則執(zhí)行“ (*p ) +;”語句后 ,p 所 指向?qū)ο蟮闹禐?

11、26 。33.假定 a 是一個一維數(shù)組,則ai 的指針訪問方式為 *(a+i) 。34.假定p 是一個指向整數(shù)對象的指針, 則用 *p 表示該整數(shù)對象。35.執(zhí)行int *p=malloc(sizeof(int)操作得到的一個動態(tài)分配的整型對象為*p 。36.假定一個結(jié)構(gòu)類型的定義為 “structCdouble* a4 ;int n; ;”,則該類型的大小為 20個字節(jié)。37.假定要動態(tài)分配一個類型為structWorker 的具有 n 個元素的數(shù)組, 并由r 指向這個動態(tài)數(shù)組,則使用的語句表達(dá)式為struct Worker* r=malloc(n*sizeof(struct Worker)

12、38. 與結(jié)構(gòu)成員訪問表達(dá)式 p->name 等價的表達(dá)式是 (*p).name 。三、寫出下列每個程序運(yùn)行后的輸出結(jié)果1. #include<stdio.h>void main() int i, s=0;for(i=1;i+) if(s>50) break;if(i%2=0) s+=i;printf("i,s=%d, %dn",i,s);結(jié)果: i,s=15, 562. #include<stdio.h>void main() char ch='*'int i, n=5;while(1) for(i=0;i<n;i

13、+) printf("%c",ch);printf("n");if(-n=0) break;3. #include<stdio.h>const int N=5;void main()int i,p=1,s=0;for(i=1;i<N;i+)p=p*i;s=s+p;printf("%5d%5d",i,p); printf("%5dn",s);4. #include<stdio.h>void main()int x=24,y=88;int i=2,p=1;do while(x%i=0 &a

14、mp;& y%i=0) p*=i; x/=i; y/=i;i+; while(x>=i && y>=i); printf("%dn",p*x*y);結(jié)果結(jié)果11122236942433結(jié)果: p*x*y=8*3*11=2645. #include<stdio.h>void main() int a9=36,25,48,24,55,40,18,66,20;int i, b1, b2;a0<=a1? (b1=a0, b2=a1):(b1=a1,b2=a0); for(i=2; i<9; i+)if(ai<b1)

15、b2=b1; b1=ai;else if(ai<b2) b2=ai;printf("%d %dn",b1,b2);結(jié)果: 18 206. #include<stdio.h>void main() int a12=76,63,54,62,40,75,80,92,77,84,44,73;int b4=60,70,90,101;int c4=0;int i,j;for(i=0;i<12;i+) j=0;while(ai>=bj) j+; cj+;for(i=0;i<4;i+)printf("%d",ci);printf(&q

16、uot;n");結(jié)果: 3 2 6 17. #include<stdio.h>void main() int a=10, b=20;結(jié)果10 2040 3540 20printf("%d %dn",a,b); int b=a+25;a*=4;printf("%d %dn",a,b);printf("%d %dn",a,b);8. #include<stdio.h>void SelectSort(int a, int n)int i,j,k,x;for(i=1;i<n;i+) / 進(jìn)行 n-1 次

17、選擇和交換 k=i-1;for(j=i;j<n;j+) if(aj<ak) k=j;x=ai-1; ai-1=ak; ak=x;void main()int i;int a6=20,15,32,47,36,28;SelectSort(a,6);for(i=0; i<6; i+) printf("%d ",ai); printf("n");結(jié)果: 15 20 28 32 36 479 #include<stdio.h>void main() int a8=4,8,12,16,20,24,28,32; int *p=a;do p

18、rintf("%d",*p); p+=2; while(p<a+8); printf("n");結(jié)果: 4 12 20 2810. #include<stdio.h>void LE(int* a, int* b) int x=*a;*a=*b; *b=x;結(jié)果15262615void main() int x=15, y=26; printf("%d %dn",x,y); LE(&x,&y);printf("%d %dn",x,y);11. #include<stdio.h&

19、gt;#include<string.h>struct Worker char name15; /姓名int age; /年齡float pay; / 工資;int Equal(struct Worker* r1, struct Worker* r2) if(strcmp(r1->name, r2->name)=0) return 1; else return 0;void main() struct Worker a4="abc",25,420,"defa",58,638, "ghin",49,560,&qu

20、ot;jklt",36,375;struct Worker x="defa"int i;for(i=0; i<4; i+)if(Equal(a+i,&x) break;if(i>=4) printf("沒有查找所需要的記錄 !n");else printf("%s %d %6.2fn",,ai.age,ai.pay);結(jié)果: defa 58 638.00四、寫出下列每個函數(shù)的功能1. int SE(int n) /n 為大于等于 1 的整數(shù) int x,s=0;printf("輸入

21、 %d 個整數(shù) : ",n);scanf("%d",&x);if(n=1) return x;s=x;while(-n) scanf("%d",&x); s+=x;return s; 函數(shù)功能:求出鍵盤上輸入的 n 個整數(shù)之和并返回。2. float FH() float x,y=0,n=0;scanf("%f",%x);while(x! =-1.0) n+; y+=x; scanf("%f",%x);if(n-0) return y; else return y/n;函數(shù)功能:求出從鍵盤

22、上輸出的一批常數(shù)的平均值,以 -1.0 作為結(jié)束輸入的標(biāo)志。3. #include<stdio.h>void WA(int a, int n) int i,k,j,x; for(i=0;i<n-1;i+) k=i; for(j=i+1;j<n;j+)if(aj>ak) k=j;x=ai; ai=ak; ak=x;a 中的 n 個整數(shù)按照從大到小的次序重新排列。函數(shù)功能:采用選擇排序的方法對數(shù)組4. #include<stdio.h>int* LJ(int a, int n) int i,k=0;for(i=1;i<n;i+)if(ai>ak

23、) k=i;return &ak;函數(shù)功能:求出數(shù)組 a 中 n 個元素的最大值元素,返回該元素的地址。5. void QC(struct StrNode* f) while(f) printf("%sn",f->name);f=f->next;假定結(jié)構(gòu)類型 StrNode 的定義如下 :stuct StrNode char name15; / 字符串域struct StrNode *next; / 指針域;函數(shù)功能:遍歷 f 單鏈表,即從頭結(jié)點開始依次輸出 f 單鏈表中每個結(jié)點的值。6. int Output(struct IntNode *f) 用返

24、回特定值 -9999 表示空表int sum=0;if(!f) return -9999; / while(f) sum+=f->data;f=f->next;return sum;假定 struct IntNode 的類型定義為:struct IntNode int data;/struct IntNode* next; / ;函數(shù)功能:對于以表頭指針為結(jié)點值域結(jié)點指針域f 的鏈表,求出并返回所有結(jié)點中data 域的值之和。7. int wr4(FILE* fptr)char ch;int c=0;fseek(fptr,0,SEEK_SET);while(1) ch=fgetc(

25、fptr); if(ch!=EOF) c+; else break;return c;函數(shù)功能: 求出一個以 fptr 為文件流的所對應(yīng)文件的長度,即所存字符的個數(shù)。五、根據(jù)下列每個題目要求編寫程序1. 編寫一個函數(shù) fun() ,首先從鍵盤上輸入一個 4 行 4 列的一個實數(shù)矩陣到一個二維數(shù)組 a44 中,接著求出主對角線上元素之和,最后返回求和結(jié)果。#include<stdio.h>double fun()double a44;double s=0;int i,j;printf(" 輸入一個 4*4 的數(shù)值矩陣 :n");for(i=0;i<4;i+)

26、for(j=0;j<4;j+) scanf("%lf",&aij);for(i=0;i<4;i+) s+=aii;i return s;void main()printf(" 主對角線上元素之和是 %lfn",fun();2. 編寫一個主函數(shù),計算 1+3+32+.+3 10的值并輸出,假定分別用 i,p,s 作為循環(huán)變量、累 乘變量和累加變量的標(biāo)識符。#include<stdio.h>void main()int i; / 用 i 作為循環(huán)變量int p=1; / 用 p 作為累乘變量int s=1; / 用 s 作為累

27、加循環(huán)變量 for(i=1;i<=10;i+) p*=3; s+=p; printf("%dn",s);3. 編寫一個主函數(shù),已知 6 a40,15 b 30,求出滿足不定方程 2a+5b=120 的全部整數(shù) 組解。如 ( 13,20) 就是其中的一組解。#include<stdio.h>void main()int a,b;for(a=6;a<=40; a+) for(b=15;b<=30;b+) if(2*a+5*b=126) printf("(%d, %d)n",a,b);"If we don't d

28、o 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 theFA's celebrations - said he wanted to meet Ivory Coast international Toure to discuss his complaint.CSKA general director

29、Roman Babaev says the matter has been "exaggerated"by theIvorian and the British media.Blatter, 77, said: "It has been decided by the Fifa congress that it is a nonsense for racism to be dealt with with fines. You can always find money from somebody to pay them."It is a nonsense

30、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."This is one of the villains we have today in our game. But it is only with harsh sanction

31、s that racism and discrimination can be washed out of football."The (lack of) air up thereFootball Association's celebrations and will League match at ChelseaWatch m Cayman Islands-based Webb, the head of Fifa's anti-racism taskforce, is in London for the 150th anniversary attend City&#

32、39;s Premier on Sunday."I am going to be at the match tomorrow and I have asked to meet YayaToure," he told BBC Sport."For me it's about how he felt and I would like to speak to him first to find out what his experience was."Uefa has opened disciplinary proceedings against CS

33、KA for the "racist behaviour of their fans" during City's 2-1 win.Michel Platini, president of European football's governing body, has also ordered an immediate investigation into the referee's actions.CSKA said they were "surprised and disappointed" by Toure's co

34、mplaint. In a statement the Russian side added: "We found no racist insults from fans ofCSKA."Baumgartner the disappointing news: Mission aborted.The supersonic descent could happen as early as Sunda.The weather plays an important role in this mission. Starting at the ground, conditions ha

35、ve to be very calm - winds less than 2 mph, with no precipitation or humidity and limited cloud cover. The balloon, with capsule attached, will move through the lower level of the atmosphere (the troposphere) where our day-to-day weather lives. It will climb higher than the tip of Mount Everest (5.5

36、 miles/8.85 kilometers), drifting even higher than the cruising altitude of commercial airliners (5.6 miles/9.17 kilometers) and into the stratosphere. As he crosses the boundary layer (called the tropopause),e can expect a lot of turbulence.The balloon will slowly drift to the edge of space at 120,000 feet (Then, I would assume, he will slowly step out onto something resembling an Olympic diving platform.Below, the Earth becomes the concrete bottom of a

溫馨提示

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

評論

0/150

提交評論