PTA理論考部分_第1頁
PTA理論考部分_第2頁
PTA理論考部分_第3頁
PTA理論考部分_第4頁
PTA理論考部分_第5頁
已閱讀5頁,還剩110頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、HW021- 3#include ;是編譯預(yù)處理命令。(1分)T F1- 5任何一個程序都必須有而且只能有一個mai n()函數(shù)。(1分)T F1- 6C語言程序是從源文件的第一條語句開始執(zhí)行的。(1分)T F1- 7C語言中的所有語句都必須以分號結(jié)束。(1分)T F1- 10以下程序段符合 C語言語法。k = 1;int k;(1分)T F1- 11C程序中定義的變量,代表內(nèi)存中的一個存儲單元。(1分)T F1- 12在C語言中,單目運算符需要2個操作數(shù)。(1分)T F1- 13若變量定義為int fahr;,則5(fahr-32)/9是符合C語言語法的表達式。(1分)T F1- 14若變量

2、定義為double x;,則x % 2是符合C語言語法的表達式。(1分)T F1-15若變量定義為int n;,當n的絕對值大于1時,則表達式1/n的值恒為0。(1分)T F 1-17 若變量定義為int x, y;,則x + y = 22是符合C語言語法的表達式。(1分)T F1-18假設(shè)賦值運算符的優(yōu)先級比算術(shù)運算符高,執(zhí)行以下程序段后,n的值為10。int n;n = 10 + 2;(1分)T FHW031-4如果變量已經(jīng)正確定義,則執(zhí)行以下程序段后,x的值不變。if (x = 20) y = 1;else y = 0;(1分)T F1-7執(zhí)行以下程序段,輸入10,輸出。double x

3、;scanf(%d, &x);printf(%.2f, x);(1分)T F1-8執(zhí)行以下程序段,輸入20,輸出。double x;scanf(%f, &x);printf(%.2f, x);(1分)T F1-9執(zhí)行以下程序段,輸入30,輸出。double x;scanf(x=%lf, &x);printf(%.2f, x);(1分)T F1-11執(zhí)行以下程序段,輸入1001 3,輸出1001#3#。int money, year;double rate;scanf(%d %lf %d , &money, &year, &rate);printf(%d#%d#%.3f, money, year

4、, rate);(1分)T F1-14如果變量已經(jīng)正確定義,則表達式fahr +與fahr + 1等價。(1分)T F1-15for語句的一般形式如下,其中的表達式1只執(zhí)行一次。for (表達式1;表達式2;表達式3)循環(huán)體語句(1分)T F1-16for語句的一般形式如下,若表達式2的值為假”則結(jié)束循環(huán)。for (表達式1;表達式2;表達式3)循環(huán)體語句(1分)T F1-18C程序中,用一對大括號括起來的多條語句稱為復(fù)合語句,復(fù)合語句在語法上被認為是一條語句。(1分)T F1-19循環(huán)體如包括有一個以上的語句,則必須用一對大括號括起來,組成復(fù)合語句,復(fù)合語句在語法上被認為是一條語句。(1分)

5、T F1-20在C語言中,僅由一個分號(;)構(gòu)成的語句稱為空語句,它什么也不做。 (1分)T F1-21執(zhí)行以下程序段,sum的值是55。int i, sum;for (i = 1; i = 10; i+)sum = sum + i;(1分)T F1-22以下程序段的功能是計算20的階乘。int i;double product;product = 0;for (i = 1; i = 20; i+)product = product * i;(1分)T F1-23執(zhí)行以下程序段,sum的值是。int i, sum;sum = 0;for (i = 1; i = 2; i+)sum = sum

6、+ i;(1分)T F1-24執(zhí)行以下程序段,sum的值是。int i;double sum;sum = 0;for (i = 2; i = 4; i = i + 2) sum = sum + 1/i;(1分)T F2- 1(2分)以下程序段()的功能是計算序列 1 + 1/2 + 1/3 + .的前N項之和。A.int i, n, sum; scanf(%d, & n);sum = 0;for (i = 1; i = n; i+)sum = sum + i;B.int i, n;double sum; scanf(%d, & n);for (i = 1; i = n; i+) sum = s

7、um + i;C.int i, n;double sum; scanf(%d, & n);sum = 0;for (i = 1; i = n; i+)sum = sum + i;D.E. int i, n;F. double sum;G. scanf(%d, & n);H. sum = 0;I. for (i = 1; i = n; i+)J. sum = sum + 1/i;K. L.M.int i, n;N.double sum;O.scanf(%d, &n);P.Q.R.S.sum = 0;for (i = 1, i = n, i+)sum = sum + i;2-2以下程序段()的功能

8、是計算 n的階乘,假設(shè)計算結(jié)果不超過雙精度范圍。(2分)A.int i, n;double product;scanf(%d, & n);product = 0;for (i = 1; i = n; i+)product = product * i;B.int i, n, product; scanf(%d, & n); product = 1;for (i = 1; i = n; i+)product = product * i;C.int i, n;double product;scanf(%d, & n);for (i = 1; i = n; i+)product = product *

9、 i;D.int i, n;double product;scanf(%d, & n);product = 1;for (i = 1; i = n; i+)product = product * i;4-2執(zhí)行以下程序段,并回答下列問題。請注意,直接填數(shù)字,前后不要加空格等任何其他字符。int fahr;double celsius;for (fahr = 91 ; fahr = 100; fah葉+)celsius = * (fahr - 32) / ;/* 語句 */printf(%4d%n, fahr, celsius);/* 語句 */語句執(zhí)行了10(1分)次語句執(zhí)行了(1分)次循環(huán)體

10、語句共執(zhí)行了10(1分)次當循環(huán)結(jié)束時,變量fahr的值是101(1分)HW041-1if-else語句的一般形式如下,其中的語句1、語句2只能是一條語句。if (表達式)語句1else語句2(1分)T F1-4為了檢查以下省略 else的if語句的分支是否正確,至少需要設(shè)計3組測試用例,即grade的取值至少有三組(小于、大于、等于 60)。if(grade 60)printf(Failn);(1分)T F1-7如果變量已經(jīng)正確定義,則執(zhí)行以下程序段后,x的值不變。x = 4;if (x mynumber )printf(Too big!n);elseprintf(Too small!n);

11、(1分)T F1-9為了檢查以下else-if語句的三個分支是否正確,至少需要設(shè)計5組測試用例,即x的取值至少有五組(小于 0的數(shù)、0、大于0且小于15的數(shù)、15和大于15的數(shù))。if (x 0)y = 0;else if (x = a & ch = A & ch = O & ch 0x=0x 0) y =1;C. else if(x =0) y = 0;D. else y = -1;E.E. y = 0;F. if(x 0) y =1;G. else if(x = 0);L. if(x 0) y= 1;M. else y = -1;if(x = 0)if(x 0) y = 1; else y

12、 = 0;else y = -1;2-8下列程序段的輸出結(jié)果是()。(2分)int main(void)int a = 2, b = -1, c = 2;if(a b)if(b 0) s = s + 1;if(a b) t = s + t;else if(a = b) t = 5; else t = 2 * s; printf(t=%dn,t);return 0;A. abB.ab0C.0aab3- 1C語言中,以下()是合法的字符常量。(2分)A. AB.zC.OD.$E.aSwitch后的常量表達式必須為整型或字符型,不能是浮點型3- 2設(shè)變量已正確定義,以下()是合法的switch語句。

13、(2分)A.switch(choice)case 1: price = ; break;case 2: price = ; break;case 3: price = ; break;case 4: price = ; break;case 1: price = ; break;default: price = ; break;B.switch(choice)case 1: price = ; break;case 2+2: price = ; break;C.D.switch(9)E.case 3:price =;break;F.case 2:price =;break;G.H.H. swi

14、tch(choice* choice+1)I. default: price = ; break;J. case 2: price = ; break;K. 3- 3設(shè)變量已正確定義,以下()是合法的switch語句。(2分)A.B. switch(op)C. defa ult: printf(Errorn); break;D. E.switch(op)case printf(%dn, value1 * value2); break;case +: printf(%dn, valuel + value2); break;case -: printf(%dn, valuel - value2);

15、 break;case *: printf(%dn, valuel * value2); break; default: printf(Errorn); break;F.switch(/)case *: printf(%dn, valuel * value2); break;case -: printf(%dn, valuel - value2); break;case +: printf(%dn, valuel + value2); break; default: printf(Errorn); break;E. 對的! !switch(op+1)default: printf(Errorn

16、); break;case *: printf(%dn, valuel * value2); break;case +: printf(%dn, valuel + value2); break;H.switch(op)case op = +: printf(%dn, valuel + value2); break; default: printf(Errorn); break;設(shè)變量已正確定義,選項()與以下程序段等價。(2分)3- 4設(shè)變量已正確定義,選項()與以下程序段不等價。(2分)switch(choice)case 1: price =;case 2: price =; defaul

17、t: price =;A.switch(choice)default: price =;case 2: price =;case 1: price =; B.price =; switch(choice)case 1: price =;case 2: price =; C.if(choice = 1)price = ; price = ; price =;else if(choice = 2)price = ; price =;elseprice =;3- 5(2分)設(shè)變量已正確定義,選項()與以下程序段不等價。switch(op)case +: printf(%d, value1 + val

18、ue2);default: printf(Error);case -: printf(%d, value1 - value2);A.B.if(op = +)C.printf(%d, value1 + value2);D.printf(Error);E.else if(op != -)F.printf(Error);G.H.printf(%d, value1 - value2);I.if(op = +)printf(%d, valuel + value2); printf(Error);printf(%d, value1 - value2); else if(op = -)printf(%d,

19、value1 - value2);else printf(Error);printf(%d, value1 - value2);J.if(op = +)printf(%d, value1 + value2);else if(op = -)printf(%d, value1 - value2);else printf(Error);K.switch(op)case +: printf(%d, value1 + value2);case -: printf(%d, value1 - value2); defa ult: printf(Error);3- 6switch (ch)case -:min

20、us+; break;case O : case 1 : case 2 : case 3 : case 4: case 5 : case 6 : case 7 : case 8 : case 9: digit +;break;default:other +; break;A.B.if(ch = -)C.minus+;D.else if(ch = 5 & ch = O & ch = 9) digit +;else other +;L.switch (ch)case O : case 1 : case 2 : case 3 : case 4:case -:minus+; break;case 5

21、: case 6 : case 7 : case 8 : case 9: digit +;break;default:other +; break;3-7設(shè)變量已正確定義,選項()與以下程序段不等價。(2分)if (x 2)if (x = 2)C.y = x + 2;D.else if (x 1)E.y = x + 1;F.G.if (x 2)H.if (x 1) y = x + 1;I.else y = x + 2;J.K.if (x 2) L.if (x 1)M.y = x + 1;N.elseO.y = x + 2;P.Q.R.if (x 2)if (x 1)y = x + 1;else

22、;elsey = x + 2;3- 9設(shè)變量已正確定義,以下()是合法的C語句。(2分)A.B. if ( n = 10 );C.D.switch ( k ) E.case 1: printf(one); break;F.case 2: printf(two); break;G.case 1: printf(one); break;H.default: printf(zero); break;I.J.K.switch ( k%2 ) L.default: printf(zero); break;M.case 1: printf(one);N.case 1+1: printf(two);O.P.

23、n = 10;switch ( k ) case n%3: printf(one);case n%4: printf(two); default: printf(zero);n%3不能在常量表達式區(qū)域出現(xiàn)3- 10判斷ch是數(shù)字字符的C語言表達式是()。(2分)A.B.0 = ch = O & ch = 1 & ch = 10設(shè)變量已正確定義,以下程序段()的功能是交換變量 x和y的值。(2分)A.B. temp = x; x = y; y =temp;C.D. x = y; y = x;E.F. y = x; x = y;G.x = x + y; y = x - y; x = x y;4-

24、3寫出以下程序段的運行結(jié)果。請注意,直接填單詞、字符或者兩者的組合,前后不要加空格等任何其他字符。double grade; scanf (%lf, &grade); if(grade mynumber )printf(Big);else printf(Small);輸入輸入輸入(1分)(1分)(1分)4- 6-1C語言中,數(shù)字字符1的值(ASCII碼)就是數(shù)字字符0的值加(1分)。請注意,直接填數(shù)字,前后不要加空格等任何其他字符。4- 725C語言中,小寫字母Z的值(ASCII碼)就是小寫字母a的值加(1分)o請注意,直接填數(shù)字,前后不要加空格等任何其他字符。4- 83C語言中,大寫字母 D

25、的值(ASCII碼)就是大寫字母A的值加(1分)。請注意,直接填數(shù)字,前后不要加空格等任何其他字符。4- 9寫出以下程序段的運行結(jié)果。請注意,直接填數(shù)字,前后不要加空格等任何其它字符。int choice;double price;scanf(%d, &choice); switch(choice)case 1: price = ; break;case 2: price = ; break;case 3: price = ; break;case 4: price = ; break; default: price = ; break;printf(%, price);/0表示寬度為0,若超

26、岀則按照實際寬度/輸入輸入 輸入 輸入 輸入4- 11寫出以下程序段的運行結(jié)果。請注意,直接填數(shù)字,前后不要加空格等任何其他字符。int choice;double price; scanf(%d, & choice); switch(choice)case 1: price =;case 2: price =; default: price =;printf(%, price);輸入輸入輸入4- 12單詞或者兩者的組合,前后不要加空格寫出以下程序段的運行結(jié)果。請注意,直接填數(shù)字、 等任何其他字符。char op;int value1, value2;scanf(%d%c%d, &value1

27、, &op, &value2); switch(op)case printf(%d, value1 + value2); default: printf(Error);case -: printf(%d, valuel - value2);r2輸入 11+1,輸出(1 分)12Error10輸入14-5,輸出9(1分)I Error(1 分) Error-90break是大坑!4-14寫出以下程序段的運行結(jié)果。請注意,直接填數(shù)字,前后不要加空格等任何其他字符。char ch;int digit, i, minus, other;digit = minus = other = 0;for(i =

28、 1; i = 5; i+)ch = getchar();switch (ch)case 0 : case 1 : case 2 : case 3 : case 4:case -:minus+; break;case 5 : case 6 : case 7 : case 8 : case 9:digit +;break;defa ult:other +; break;輸入R-e-d,digit的值是0I 2(1分),minus的值是1I 3(1分),other的值是1(1分)1I 3r 1輸入1+4-5, digit的值是分)(1分),min us的值是丨(1分),other的值是1(1輸入1

29、67or,digit的值是2r 12(1分),minus的值是(1分),other的值是1(1分)4-15if (表達式1)if (表達式2)語句1;elseif (表達式3)語句2;else語句3;當表達式1為True(1分)且表達式True(1分)時,執(zhí)行語句1 ;當表達式1為True(1分)且表達式2為False(1分)且表達式3為True(1分)時,執(zhí)行語句2;當表達式1為True(1分)且表達式2為1False(1分)且表達式3為False(1分)時,執(zhí)行語句3。4-16寫出以下程序段 A和程序段B的運行結(jié)果。請注意,直接填字母、單詞或者兩者的組合, 前后不要加空格等任何其他字符。/

30、*程序段A */for( i = 1; i 7; i+)scanf(%d, &score);score = score/10 ;switch(score) case 10: case 9: case 8: case 7: case 6:grade = P; break;defa ult:grade = F; break; putchar(grade);printf(Thanks);PPFPPPThanks輸入 100 90 50 82 72 69, 輸出(1 分)/*程序段B */for( i = 1; i 7; i+)scanf(%d, &score);score = score/10 ;s

31、witch(score) case 10: case 9: case 8: case 7: case 6:grade = P; break;defa ult:grade = F: break;putchar(grade);printf(Thanks);Thanks輸入 100 90 50 82 72 69, 輸出(1 分)。4-17寫出以下程序段A和程序段B的運行結(jié)果。請注意,直接填字母,前后不要加空格等任何其他字符。/*程序段A */char grade;int i, score;for( i = 1; i 6; i+)scanf(%d, &score);score = score/10 ;switch(score) case 10:case 9:case 8: grade = A; break;case 7: grade = P; break;default: grade = F; break;p

溫馨提示

  • 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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論