(完整版)全國計(jì)算機(jī)等級(jí)考試二級(jí)教程--C語言程序設(shè)計(jì)課后習(xí)題答案_第1頁
(完整版)全國計(jì)算機(jī)等級(jí)考試二級(jí)教程--C語言程序設(shè)計(jì)課后習(xí)題答案_第2頁
(完整版)全國計(jì)算機(jī)等級(jí)考試二級(jí)教程--C語言程序設(shè)計(jì)課后習(xí)題答案_第3頁
(完整版)全國計(jì)算機(jī)等級(jí)考試二級(jí)教程--C語言程序設(shè)計(jì)課后習(xí)題答案_第4頁
(完整版)全國計(jì)算機(jī)等級(jí)考試二級(jí)教程--C語言程序設(shè)計(jì)課后習(xí)題答案_第5頁
已閱讀5頁,還剩24頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、全國計(jì)算機(jī)等級(jí)考試二級(jí)教程 -C 語言程序設(shè)計(jì)課后習(xí)題答案第一章1.1 EXE1.2 C OBJ EXE1.3 順序 選擇 循環(huán)第二章一. 選擇題2.1 B 2.2 D 2.3 B 2.4 A 2.5 C 2.6 A 2.7 B2.8 B 2.9 D 2.10 C 2.11 B 2.12 B 2.13 A二. 填空題2.14 11 122.15 4.2 4.22.16 定義 執(zhí)行語句2.17 關(guān)鍵字 用戶標(biāo)識(shí)符2.18 int float double2.19 float a1=1; float a2=1;2.20 存儲(chǔ)單元2.21 3.52.22 (a*b)/c a*b/c a/c*b2.2

2、3 把常量 10 賦給變量 s2.24 位 1 或 02.25 8 127 0111111 -128 100000002.26 32767 -32768 10000000000000002.27 10 8 16三. 上機(jī)改錯(cuò)題2.28#include stdio.h; 刪除行尾的 ;*要緊靠“ / ” ,即應(yīng)為“ /*”和“ */注釋符號(hào)不可嵌套使用main(); / * main function * /刪除 ) 后的 ;, 注釋中的函數(shù)開始處遺失了一個(gè)“ ”float r ,s ; /*/*r is radius*/,/* s is area of circuilar*/*/r = 5.0

3、 ;s = 3.14159 * r * r ;printf(%fn,s) 行尾遺失了“ ; ” 函數(shù)結(jié)束處遺失了一個(gè)“ ”2.29#include stdio.hmain /* main function */ main后遺失了“ () ”float a,b,c,v; /*a,b,c are sides, v is volume of cube */ a=2.0; b=3.0; c=4.0 行尾遺失了“ ; ”v=a*b*c;printf(%fn, v) 行尾遺失了“ ; ”第三章一. 選擇題3.1 C 3.2 C 3.3 D 3.4 C 3.5 D 3.6 B 3.7 C 3.8 D 3.9

4、 A 3.10 B3.11 C 3.12 D 3.13 D 3.14 A 3.15 C 3.16 C 3.17 C 3.18無答案 3.19 C 3.20 B二. 填空題3.21 (1)-2002500(2)i=-200,j=2500(3)i=-200j=25003.22 12 0 03.23 一條語句 ;3.24 ;3.25 100,25.81,1.89234 100 25.81 1.89234 100 25.81 1.892343.26 x=127,x= 127,x= 177,x= 7f,x= 1273.27 x=127,x=127 ,x=$127 ,x=$000127,x=%06d3.2

5、8 a=513.789215,a= 513.79,a= 513.78921500,a= 513.78921500三 . 編程題和改錯(cuò)題3.29 修改后的程序如下:main()double a,b,c,s,v; printf(input a,b,c:); scanf(%lf%lf%lf,&a,&b,&c); s =a*b;v=a*b*c; printf(a=%f,b=%f,c=%fn, a,b,c); printf(s=%f,v=%fn,s,v);3.30#includemain()int a=560,b=60;printf(560 minute is %d hour and %d minute

6、.n,a/b,a%b); 3.31#includemain()int a,b; a=1500;b=350;printf(a div b is : %dn,a/b); printf(a mod b is : %dn,a%b);3.32#include main() double a,b,c,ave;printf (input 3 double number : n); scanf (%lf%lf%lf,&a,&b,&c);printf (%.1fn,(a+b+c)/3);3.33#includevoid main()int a,b,c,t; printf( 請(qǐng)依次輸入整數(shù) a,b,c:); sc

7、anf(%d%d%d,&a,&b,&c);printf(n 你輸入的值是 : a=%d,b=%d,c=%dn,a,b,c); t=b;b=a;a=c;c=t;printf( 交換之后的值是 :a=%d,b=%d,c=%dn,a,b,c); 第四章一. 選擇題4.1 A 4.2 A 4.3 A 4.4 D 4.5 C 4.6 A 4.7 B 4.8 C 4.9 D 4.10 C 二. 填空題4.11 非 0 04.12 = = 同級(jí) = ! = 同級(jí)4.13 ! & |4.15 !4.16 a = b | a 4 | x -44.17 14.18 x 04.19 3 2 24.20 *#三 .

8、編程題4.21 略4.22#include /* 檢查日期的合法性 */int checkdate(int year , int month, int day)if(year 2005)printf( 輸入的年份無效 !n); return 0;else if(month 12)printf( 輸入的月份無效 !n); return 0;else if(day 31)printf( 輸入的日期無效 !n); return 0;elseswitch(month)case 4:case 6:case 9:case 11:if(day 30)printf( 輸入的日期無效 !n); return 0

9、;break;case 2:if(year%4 = 0 & year%100 != 0) | year%400 = 0) if(day 29)printf( 輸入的日期無效 !n); return 0;elseif(day 28)printf( 輸入的出生日期無效 !n);return 0;break;/* end of switch(m0)*/return 1;void main()int y0, m0, d0; /* 生日 */int y1, m1, d1; /* 當(dāng)前日期 */int years, months, days; /* 實(shí)足年齡 */printf( 請(qǐng)輸入學(xué)生的生日 :);

10、scanf(%d%d%d, &y0,&m0,&d0);if(checkdate(y0, m0, d0)printf( 請(qǐng)輸入當(dāng)前日期 :); scanf(%d%d%d, &y1,&m1,&d1);/* 當(dāng)前日期合法性檢查 */if(!checkdate(y1, m1, d1)return;else if(y0 y1)printf( 出生年份比當(dāng)前年份晚 !n);return;else if(y0 = y1)if(m0 m1)printf( 出生年月比當(dāng)前年月晚 !n);return;else if(m0 = m1)if(d0 d1)printf( 出生年月日比當(dāng)前年月日晚 !n);return

11、;/* 計(jì)算實(shí)足年齡 */ years = y1 - y0; months = m1 - m0; days = d1 - d0;/* 修正實(shí)足年齡天數(shù) */ if(days 0) months-;switch(m1)case 1: case 5: case 7: case 10: case 12: days += 30; break;case 2: case 4: case 6: case 8: case 9: case 11: days += 31; break;case 3:if(y1%4 = 0 & y1%100 != 0) | y1%400 = 0) days += 29; else

12、days += 28;break;/* end of switch(m1) */* end of if(days 0) */* 修正實(shí)足年齡月數(shù) */ if(months 0)months += 12;years-;/* end of if(months b)? a:b; max=(tempc)? temp:c;printf (n);%d.n,max);printf ( 你輸入的數(shù)中最大的是 4.25(1) 不嵌套的 if 語句#includevoid main()int x,y;printf(input x :); scanf(%d,&x);if ( x-5 & x0 & x=10 | x=

13、-5)printf(errorn);(2) 嵌套的 if 語句#includevoid main()int x,y; printf(input x :); scanf(%d,&x);printf(n);if(x -5)printf(y is %d.n,y=x);elseprintf(error!n);if(0 = x)printf(y is %d.n,y=x-1);if(x 0)if(x -5 & x0 & x10 )printf(y is %d.n,y=x+1); elseprintf(error!n);(4) switch 語句#includevoid main()int x,y; pri

14、ntf(input x : ); scanf(%d,&x);switch (x)case -4:case -3:case -2:case -1:printf(y is %d.n,y=x); break;case 0:printf(y is %d.n,y=x-1); break;case 1:case 2:case 3:case 4:case 5:case 6:case 7:case 8:case 9:printf(y is %d.n,y=x+1); break;default: printf(error!n);第五章選擇題5.1 D 5.2 C 5.3 B 5.4 C 5.5 C 5.6 B

15、5.7 D 5.8 A 5.9 D 5.10 D 二. 填空題5.11 5 4 65.12 死循環(huán)5.13 -15.14 115.15 d=1.0 k+ k=0 x三 . 編程題5.17#includevoid main()int i;int sig = 1;int sum = 0;for(i=1; i=101; i+,i+)sum += sig*i;sig *= -1;printf(sum=%dn, sum);5.18(1)#includevoid main()int i;double m=1.0;double e = 1.0;for(i=1; i= 0.0004) m *= i;e +=

16、1/m; i+; printf(e=%fn,e);5.19#includevoid main() int year;int col = 0;for(year=1600; year=2000; year+)if(year%4 = 0 & year%100 != 0) | year%400 = 0) printf(%dt, year); col+;if(col%5 = 0) printf(n); printf(n);5.20 #include #define N 7 void main()int i;int j;int m;int k = N/2;for(i=0; i m = i-k;if(m 0

17、)m *= -1;for(j=0; j printf( );for(j=0; j= 0 & striLoop = 9) num = 10*num + (striLoop - 0); iLoop+; printf(%dn,num);6.22 #include #include#define N 80void main() char strN;int num = -1;dogets(str);num+;while(strcmp(str , EOF);printf( 您輸入了 %d 行字符! n,num);6.23#include#define N 80void main()char strN;in

18、t iLoop = 0;int num = 0;gets(str);while(striLoop & iLoop = a & striLoop = z)num+;iLoop+;printf( 您輸入了字符中有 %d 個(gè)小寫字母! n,num); 6.24#includevoid main()int line;int iLoop1;int iLoop2;printf( 請(qǐng)輸入圖案的行數(shù) ( 不大于 26):); scanf(%d, &line);for(iLoop1 = 0; iLoop1 line; iLoop1+)for(iLoop2 = 0; iLoop2 line - iLoop1; i

19、Loop2+) printf( );for(iLoop2 = 0; iLoop2 2*iLoop1+1; iLoop2+) printf(%c,iLoop1 + A); printf(n);第七章一. 選擇題7.1 C 7.2 C 7.3 B 7.4 C 7.5 A 7.6 D 7.7 A二. 填空題7.8 127.9 9.0000007.10 47.11 n=1 s7.12 =y z*x7.13 1 s*i 0 f(k)三 . 程序調(diào)試和編程題7.14 fun(int n) int k,yes;for(k=2; k=n/2; k+)if(n%k = 0) yes = 0; break; el

20、se yes = 1; return yes;7.15int mymod(int a, int b) return a%b;7.16 double fun(int n) double sum = 0;int iLoop;int sig = -1;for(iLoop=1; iLoop=n; iLoop+) sig *= -1;sum += sig*1.0/iLoop;return sum;7.17 double fun(int n) double t = 1.0; int iLoop; long tmp;for(iLoop=2; iLoop=n; iLoop+) tmp = iLoop*iLoo

21、p;t -= 1.0/tmp; return t;7.18#include#includedouble fun(double x)return x*x + 5*x + 4;void main()int x = 2;printf(y1=%fn, fun(x); printf(y2=%fn, fun(x+15); printf(y3=%fn, fun(sin(x); 第八章一. 選擇題8.1 A 8.2 B 8.3 B 8.4 C 8.5 B 8.6 B 8.7 C 8.8 D 8.9 B 8.10 C 8.11 C 8.12 C 二. 填空題8.13 1108.14 7 18.15 (1)cha

22、r *p=&ch; (2) p=&ch; (3)scanf(%c,p); (4)*p=A; (5)printf(%c,*p);8.16 (1)s=p+3; (2)s=s-2 (3)50 (4)*(s+1) (5)2 (6)10 20 30 40 50三 . 編程題8.17void fun(double x, double y, double *sum, double *div)*sum = x + y;*div = x - y;return;8.18void fun(double x, double y, double z, double *max, double *min)*max = x;

23、*min = x;if(*max y)*max = y;if(*max y)*min = y;if(*min z)*min = z;return;第九章一. 選擇題9.1 D 9.2 A 9.3 A 9.4 C 9.5 C 9.6 A 9.7 B 9.8 D 9.9 C 9.10 C9.11 C 9.12 D 9.13 D 9.14 A 9.15 A 9.16 A 9.17 C 9.18 C填空題9.19 9 09.20 69.21 129.22 39.23 27219.24 -850,2,09.25 k=p k9.26 (c=getchar() c-A三 . 編程題9.27#include#

24、define N 81int main()int counter10 = 0;int iLoop = 0; char strN;gets(str); while(striLoop)if(striLoop = 0 & striLoop = 9)counterstriLoop - 0+;iLoop+;for(iLoop=0; iLoop 10; iLoop+)printf(%d - %dn, iLoop, counteriLoop); return 0;9.28void fun(int array, int arraysize, int start) int iLoop;if(start arra

25、ysize-1)if(start =0) start = 1;for(iLoop = start; iLoop arraysize; iLoop+) arrayiLoop-1 = arrayiLoop; for(iLoop = 0; iLoop arraysize; iLoop+) printf(No.%d = %dn, iLoop, arrayiLoop);9.29int fun(int arry1, int arry2, int arrysize) int iLoop;int counter = 0; for(iLoop = 0; iLoop arrysize; iLoop+) if(ar

26、ry1iLoop % 2) arry2counter+ = arry1iLoop; return counter;9.30 void fun(char array, int arraysize) int iLoop1; int iLoop2;char temp;/* 冒泡排序 */for(iLoop1 = 0; iLoop1 arraysize - 1; iLoop1+)for(iLoop2 = 0; iLoop2 arraysize - 1 - iLoop1; iLoop2+) if(arrayiLoop2 arrayiLoop2 + 1)temp = arrayiLoop2; arrayi

27、Loop2 = arrayiLoop2 + 1; arrayiLoop2 + 1 = temp;9.31 #includevoid fun(int array, int arraysize, int inertNumber)int iLoop;int iLoop2;if(array0 arrayarraysize-1)for(iLoop = 0; iLoop inertNumber)for(iLoop2 = arraysize - 1; iLoop2 = iLoop; iLoop2-) arrayiLoop2 + 1 = arrayiLoop2;arrayiLoop = inertNumber

28、; break;if(iLoop = arraysize)arrayarraysize = inertNumber;elsefor(iLoop = 0; iLoop arraysize; iLoop+)if(arrayiLoop = iLoop; iLoop2-) arrayiLoop2 + 1 = arrayiLoop2;arrayiLoop = inertNumber; break;if(iLoop = arraysize) arrayarraysize = inertNumber;int main()int iLoop;int a20 = 7,6,5,3,2,1;for(iLoop =

29、0; iLoop 6; iLoop+) printf(%d , aiLoop);printf(n);fun(a, 6, 0);for(iLoop = 0; iLoop 7; iLoop+) printf(%d , aiLoop);printf(n);fun(a, 7, 4);for(iLoop = 0; iLoop 8; iLoop+) printf(%d , aiLoop);printf(n);fun(a, 8, 8);for(iLoop = 0; iLoop 9; iLoop+)printf(%d , aiLoop);printf(n);return 0;9.32int fun(int n

30、umber , int array)int iLoop = 0;int iLoop2;int binLen;int midNumber;int div;int remain;midNumber = number;dodiv = midNumber/2; remain = midNumber%2; midNumber = div; arrayiLoop+ = remain; while(midNumber);binLen = iLoop;for(iLoop2 = 0, iLoop = binLen - 1; iLoop2 iLoop; iLoop2+, iLoop-) midNumber = a

31、rrayiLoop2; arrayiLoop2 = arrayiLoop; arrayiLoop = midNumber;return binLen;9.33#include#include #define N 15void fun(int array, int arraysize)int x;int iLoop;int iLoop2;for(iLoop = 0; iLoop 0)x = rand()%20; iLoop2 = 0;iLoop2+;while(iLoop2 iLoop); arrayiLoop = x;int main()int aN;int iLoop;fun(a, N);f

32、or(iLoop = 0; iLoop N; iLoop+) printf(%dn, aiLoop);return 0;第十章一. 選擇題10.1 C 10.2 B 10.3 C 10.4 B 10.5 C 10.6 A 10.7 C 10.8 A 10.9 C 10.10 C 二. 填空題10.11 GFEDCB10.12 XYZ10.13 SO10.14 1010.15 Itis10.16 strlen(str)-1 j-10.17 310.18 goodgood !三 . 編程題10.19char* mygets(char *str)int iLoop = 0;char ch;while

33、(ch=getchar() != n)striLoop+ = ch;striLoop = 0;return str;char * myputs(char *str) int iLoop = 0; while(striLoop) putchar(striLoop+); putchar(n); return str;10.20#include#includeint fun(char *str) int len;int iLoop1;int iLoop2;int result = 1;len = strlen(str);for(iLoop1 = 0, iLoop2 = len - 1; iLoop1

34、 len) return NULL;ch = strpos;for(iLoop = pos; iLoop len - 1; iLoop+) striLoop = striLoop + 1; strlen-1 = 0; return ch;第十一章 一. 選擇題11.1 D 11.2 B 11.3 A 11.4 C二. 填空題11.5 IJKLEFGHABCD11.6 711.7 811.8 *(s+j) i+1 i11.9 1711.10 (*fun)() (*fun)(a+i*h)/h mypoly三 . 編程題11.11 #include #include #define N 81 int

35、 main(int argc, char *argv) char sig;int dig; int pos;char strN = 0; char outStrN = 0;if(argc 2)sig = -;dig = 10;elsesig = argv10;dig = argv11 - 0;printf( 請(qǐng)輸入一個(gè)字符串: ); gets(str);if(sig = -)pos = strlen(str) - dig;if(pos dig)pos = dig;outStrpos = 0;printf( 處理后的字串為: ); printf(%sn, outStr);return 0;11.

36、12#include #include void movebin(char *bin) int len; int iLoop;len = strlen(bin);for(iLoop = len; iLoop 0; iLoop-) biniLoop = biniLoop - 1; return;void fun(int n, char *bin) int pos;pos = strlen(bin); if(n = 0) return; if(n = 1) movebin(bin); bin0 = 1; return; movebin(bin); bin0 = (n%2) + 0;n /= 2;

37、fun(n, bin); return;int main() int a = 4;char bin50 = ;fun(a, bin); printf(%sn, bin);return 0; 11.13#include long fun(int n) if(n = 1) return n;elsereturn fun(n-1) + n;int main() int num; int sum;printf( 請(qǐng)輸入一個(gè)自然數(shù): ); scanf(%d, &num);sum = fun(num);printf( 結(jié)果是: %dn, sum);return 0;11.14#includeint fun

38、(int n)if(n = 0 | n = 1) return 1;elsereturn fun(n-1) + fun(n-2);int main()int num; int result;printf( 請(qǐng)輸入一個(gè)自然數(shù): );scanf(%d, &num);result = fun(num);printf( 斐波拉契級(jí)數(shù)為: %dn, result);return 0;第十二章一. 選擇題12.1 B 12.2 B 12.3 A 12.4 C 12.5 D 12.6 B 12.7 A 12.8 A二. 填空題12.9 2,5,1,2,3,-212.10 2468第十三章一. 選擇題13.1

39、 A 13.2 C 13.3 B 13.4 C 13.5 D 13.6 D 13.7 D二. 填空題13.8 ar=9 ar=9 ar=1113.9 int* s *b三 . 編程題13.10#define MYALPHA(C) (C=A & C=a & C=z) ? 1 : 013.11#define SWAP(t,x,y) t tmp; tmp=x; x=y; y=tmp;13.12#include#include int main()int *p;int tmp;int iLoop;int iLoop2;p = (int *)malloc(sizeof(int)*3);scanf(%d%

40、d%d, p,p+1,p+2); for(iLoop = 0; iLoop 2; iLoop+) for(iLoop2 = 0; iLoop2 *(p + iLoop2 + 1) tmp = *(p + iLoop2);*(p + iLoop2) = *(p + iLoop2 + 1);*(p + iLoop2 + 1) = tmp; printf(%d %d %dn, *p, *(p+1), *(p+2);free(p); p = NULL; return 0; 第十四章一. 選擇題14.1 D 14.2 D 14.3 D 14.4 A 14.5 C 14.6 C 14.7 C 14.8 B

41、二. 填空題14.9 struct link *next14.10 p-next mp-data14.11 (struct list*) struct list struct list* struct list return h三 . 編程題14.12 #include #define N 3struct stud char num5, name10;int s4; double ave; ;void readrec(struct stud array, int size)int iLoop;for(iLoop=0; iLoop scanf(%s%s%d%d%d%d, arrayiLoop.n

42、um, arrayiL, &arrayiLoop.s0, &arrayiLoop.s1,&arrayiLoop.s2, &arrayiLoop.s3);arrayiLoop.ave = (arrayiLoop.s0 + arrayiLoop.s1 + arrayiLoop.s2 + arrayiLoop.s3)/4.0;return;void writerec(struct stud array, int size)int iLoop;for(iLoop=0; iLoop printf(%st%st%dt%dt%dt%dt%fn, arrayiLoop.num,arrayiLo

43、,arrayiLoop.s0, arrayiLoop.s1,arrayiLoop.s2,arrayiLoop.s3, arrayiLoop.ave);return;int main() struct stud stuN;readrec(stu, N); writerec(stu, N);return 0;14.13#include#include#define N 100struct nodeint data;struct node* next;int seekMaxValue(struct node *pNode) int max;struct node* pMove;pMove = pNode; max = pMove-data; pMove

溫馨提示

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

評(píng)論

0/150

提交評(píng)論