logo资料库

C程序设计语言第二版英文答案.pdf

第1页 / 共530页
第2页 / 共530页
第3页 / 共530页
第4页 / 共530页
第5页 / 共530页
第6页 / 共530页
第7页 / 共530页
第8页 / 共530页
资料共530页,剩余部分请下载后查看
Table of Contents Index
The C Programming Language Exercise
The C Programming Language Exercise 1-1
The C Programming Language Exercise 1-2
The C Programming Language Exercise 1-3
The C Programming Language Exercise 1-4
The C Programming Language Exercise 1-5
The C Programming Language Exercise 1-6
The C Programming Language Exercise 1-7
The C Programming Language Exercise 1-8
The C Programming Language Exercise 1-9
The C Programming Language Exercise 1-10
The C Programming Language Exercise 1-11
The C Programming Language Exercise 1-12
The C Programming Language Exercise 1-13
The C Programming Language Exercise 1-14
The C Programming Language Exercise 1-15
The C Programming Language Exercise 1-16
The C Programming Language Exercise 1-17
The C Programming Language Exercise 1-18
The C Programming Language Exercise 1-19
The C Programming Language Exercise 1-20
The C Programming Language Exercise 1-21
The C Programming Language Exercise 1-22
The C Programming Language Exercise 1-23
The C Programming Language Exercise 1-24
The C Programming Language Exercise 2-1
The C Programming Language Exercise 2-2
The C Programming Language Exercise 2-3
The C Programming Language Exercise 2-4
The C Programming Language Exercise 2-5
The C Programming Language Exercise 2-6
The C Programming Language Exercise 2-7
The C Programming Language Exercise 2-8
The C Programming Language Exercise 2-9
The C Programming Language Exercise 2-10
The C Programming Language Exercise 3-1
The C Programming Language Exercise 3-2
The C Programming Language Exercise 3-3
The C Programming Language Exercise 3-4
The C Programming Language Exercise 3-5
The C Programming Language Exercise 3-6
The C Programming Language Exercise 4-1
The C Programming Language Exercise 4-2
The C Programming Language Exercise 4-3
The C Programming Language Exercise 4-4
The C Programming Language Exercise 4-5
The C Programming Language Exercise 4-6
The C Programming Language Exercise 4-7
The C Programming Language Exercise 4-8
The C Programming Language Exercise 4-12
The C Programming Language Exercise 4-13
The C Programming Language Exercise 4-14
The C Programming Language Exercise 5-1
The C Programming Language Exercise 5-2
The C Programming Language Exercise 5-3
The C Programming Language Exercise 5-4
The C Programming Language Exercise 5-5
The C Programming Language Exercise 5-6
The C Programming Language Exercise 5-7
The C Programming Language Exercise 5-8
The C Programming Language Exercise 5-9
The C Programming Language Exercise 5-10
The C Programming Language Exercise 5-11
The C Programming Language Exercise 5-13
The C Programming Language Exercise 5-14
The C Programming Language Exercise 6-1
The C Programming Language Exercise 6-3
The C Programming Language Exercise 6-4
The C Programming Language Exercise 6-5
The C Programming Language Exercise 7-1
The C Programming Language Exercise 7-2
The C Programming Language Exercise 7-3
The C Programming Language Exercise 7-6
The C Programming Language Exercise 7-8
The C Programming Language Exercise 7-9
The C Programming Language Exercise 8-1
The C Programming Language Exercise 8-3
The C Programming Language Exercise 8-4
The C Programming Language Exercise 8-6
《C 程序设计语言》英文 第 2 版的课后习题与答案
《C 程序设计语言》英文第 2 版的课后习题与答案 Table of Contents Index The C Programming Language Exercise ........................................................................................ 4 The C Programming Language Exercise 1-1 .............................................................................. 247 The C Programming Language Exercise 1-2 .............................................................................. 248 The C Programming Language Exercise 1-3 .............................................................................. 249 The C Programming Language Exercise 1-4 .............................................................................. 250 The C Programming Language Exercise 1-5 .............................................................................. 251 The C Programming Language Exercise 1-6 .............................................................................. 253 The C Programming Language Exercise 1-7 .............................................................................. 254 The C Programming Language Exercise 1-8 .............................................................................. 255 The C Programming Language Exercise 1-9 .............................................................................. 256 The C Programming Language Exercise 1-10 ............................................................................ 258 The C Programming Language Exercise 1-11 ............................................................................ 260 The C Programming Language Exercise 1-12 ............................................................................ 263 The C Programming Language Exercise 1-13 ............................................................................ 264 The C Programming Language Exercise 1-14 ............................................................................ 269 The C Programming Language Exercise 1-15 ............................................................................ 280 The C Programming Language Exercise 1-16 ............................................................................ 281 The C Programming Language Exercise 1-17 ............................................................................ 285 The C Programming Language Exercise 1-18 ............................................................................ 286 The C Programming Language Exercise 1-19 ............................................................................ 290 The C Programming Language Exercise 1-20 ............................................................................ 292 The C Programming Language Exercise 1-21 ............................................................................ 294 The C Programming Language Exercise 1-22 ............................................................................ 297 The C Programming Language Exercise 1-23 ............................................................................ 299 The C Programming Language Exercise 1-24 ............................................................................ 326 The C Programming Language Exercise 2-1 .............................................................................. 335 The C Programming Language Exercise 2-2 .............................................................................. 336 The C Programming Language Exercise 2-3 .............................................................................. 338 The C Programming Language Exercise 2-4 .............................................................................. 343 The C Programming Language Exercise 2-5 .............................................................................. 346 The C Programming Language Exercise 2-6 .............................................................................. 352 The C Programming Language Exercise 2-7 .............................................................................. 353 1
《C 程序设计语言》英文第 2 版的课后习题与答案 The C Programming Language Exercise 2-8 .............................................................................. 354 The C Programming Language Exercise 2-9 .............................................................................. 356 The C Programming Language Exercise 2-10 ............................................................................ 357 The C Programming Language Exercise 3-1 .............................................................................. 359 The C Programming Language Exercise 3-2 .............................................................................. 365 The C Programming Language Exercise 3-3 .............................................................................. 369 The C Programming Language Exercise 3-4 .............................................................................. 372 The C Programming Language Exercise 3-5 .............................................................................. 375 The C Programming Language Exercise 3-6 .............................................................................. 377 The C Programming Language Exercise 4-1 .............................................................................. 379 The C Programming Language Exercise 4-2 .............................................................................. 381 The C Programming Language Exercise 4-3 .............................................................................. 385 The C Programming Language Exercise 4-4 .............................................................................. 387 The C Programming Language Exercise 4-5 .............................................................................. 391 The C Programming Language Exercise 4-6 .............................................................................. 396 The C Programming Language Exercise 4-7 .............................................................................. 403 The C Programming Language Exercise 4-8 .............................................................................. 405 The C Programming Language Exercise 4-12 ............................................................................ 406 The C Programming Language Exercise 4-13 ............................................................................ 408 The C Programming Language Exercise 4-14 ............................................................................ 409 The C Programming Language Exercise 5-1 .............................................................................. 412 The C Programming Language Exercise 5-2 .............................................................................. 413 The C Programming Language Exercise 5-3 .............................................................................. 419 The C Programming Language Exercise 5-4 .............................................................................. 422 The C Programming Language Exercise 5-5 .............................................................................. 424 The C Programming Language Exercise 5-6 .............................................................................. 427 The C Programming Language Exercise 5-7 .............................................................................. 431 The C Programming Language Exercise 5-8 .............................................................................. 433 The C Programming Language Exercise 5-9 .............................................................................. 435 The C Programming Language Exercise 5-10 ............................................................................ 438 The C Programming Language Exercise 5-11 ............................................................................ 440 The C Programming Language Exercise 5-13 ............................................................................ 463 The C Programming Language Exercise 5-14 ............................................................................ 480 The C Programming Language Exercise 6-1 .............................................................................. 483 2
《C 程序设计语言》英文第 2 版的课后习题与答案 The C Programming Language Exercise 6-3 .............................................................................. 491 The C Programming Language Exercise 6-4 .............................................................................. 499 The C Programming Language Exercise 6-5 .............................................................................. 506 The C Programming Language Exercise 7-1 .............................................................................. 508 The C Programming Language Exercise 7-2 .............................................................................. 511 The C Programming Language Exercise 7-3 .............................................................................. 514 The C Programming Language Exercise 7-6 .............................................................................. 516 The C Programming Language Exercise 7-8 .............................................................................. 520 The C Programming Language Exercise 7-9 .............................................................................. 522 The C Programming Language Exercise 8-1 .............................................................................. 523 The C Programming Language Exercise 8-3 .............................................................................. 524 The C Programming Language Exercise 8-4 .............................................................................. 526 The C Programming Language Exercise 8-6 .............................................................................. 528 3
《C 程序设计语言》英文第 2 版的课后习题与答案 The C Programming Language Exercise 整理:Xiao Guan(cnguan@gmail.com, msn:ghpcn@hotmail.com,qq:237811553) 本答案为经典的 c 圣经《c 程序设计语言》英文的配 套答案,所列页码均为英文版的。本想整理为 pdf 格 式,考虑到程序能直接运行,最终还是决定为网页格 式,希望能给大家的学习带来帮助!感谢给出答案的 程序工程师,恕不列出他们名字 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 1.10 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.18 1.19 1.20 1.21 1.22 1.23 1.24 2.01 2.02 2.03 2.04 2.05 2.06 2.07 2.08 2.09 2.10 3.01 3.02 3.03 3.04 3.05 3.06 4.01 4.02 4.03 4.04 4.05 4.06 4.07 4.08 4.12 4.13 4.14 5.01 5.02 5.03 5.04 5.05 5.06 5.07 5.08 5.09 5.10 5.11 5.13 5.14 6.01 6.03 6.04 6.05 7.01 7.02 7.03 7.06 7.08 7.09 8.01 8.03 8.04 8.06 Answer to Exercise 1-1 Run the "hello, world" program on your system. Experiment with leaving out parts of the program, to see what error messages you get. Murphy's Law dictates that there is no single correct answer to the very first exercise in the book. Oh well. Here's a "hello world" program: #include int main(void) { printf("hello, world\n"); return 0; } 4
《C 程序设计语言》英文第 2 版的课后习题与答案 As you can see, I've added a return statement, because main always returns int, and it's good style to show this explicitly. Answer to Exercise 1-2 Experiment to find out what happens when printf 's argument string contains \c, where c is some character not listed above. By 'above', the question is referring to: \n (newline) \t (tab) \b (backspace) \" (double quote) \\ (backslash) We have to tread carefully here, because using a non-specified escape sequence invokes undefined behaviour. The following program attempts to demonstrate all the legal escape sequences, not including the ones already shown (except \n , which I actually need in the program), and not including hexadecimal and octal escape sequences. #include int main(void) { printf("Audible or visual alert. \a\n"); printf("Form feed. \f\n"); printf("This escape, \r, moves the active position to the initial position of the current line.\n"); printf("Vertical tab \v is tricky, as its behaviour is unspecified under certain conditions.\n"); return 0; } Answer to Exercise 1-3 Modify the temperature conversion program to print a heading above the table. #include int main(void) { float fahr, celsius; int lower, upper, step; lower = 0; upper = 300; step = 20; printf("F C\n\n"); fahr = lower; while(fahr <= upper) { celsius = (5.0 / 9.0) * (fahr - 32.0); printf("%3.0f %6.1f\n", fahr, celsius); 5
《C 程序设计语言》英文第 2 版的课后习题与答案 fahr = fahr + step; } return 0; } Answer to Exercise 1-4 Write a program to print the corresponding Celsius to Fahrenheit table. #include int main(void) { float fahr, celsius; int lower, upper, step; lower = 0; upper = 300; step = 20; printf("C F\n\n"); celsius = lower; while(celsius <= upper) { fahr = (9.0/5.0) * celsius + 32.0; printf("%3.0f %6.1f\n", celsius, fahr); celsius = celsius + step; } return 0; } Answer to Exercise 1-5 Modify the temperature conversion program to print the table in reverse order, that is, from 300 degrees to 0. This version uses a while loop: #include int main(void) { float fahr, celsius; int lower, upper, step; lower = 0; upper = 300; step = 20; printf("C F\n\n"); celsius = upper; while(celsius >= lower) { fahr = (9.0/5.0) * celsius + 32.0; printf("%3.0f %6.1f\n", celsius, fahr); celsius = celsius - step; } return 0; 6
《C 程序设计语言》英文第 2 版的课后习题与答案 } This version uses a for loop: #include int main(void) { float fahr, celsius; int lower, upper, step; lower = 0; upper = 300; step = 20; printf("C F\n\n"); for(celsius = upper; celsius >= lower; celsius = celsius - step) { fahr = (9.0/5.0) * celsius + 32.0; printf("%3.0f %6.1f\n", celsius, fahr); } return 0; } Chris Sidi notes that Section 1.3 Has a short For statement example, and "Based on that example, I think the solution to 1.5: a) should do fahr to celsius conversion (whereas the solutions on your page do celsius to fahr) b) should be similar to the example and as small." He offers this solution: #include /* print Fahrenheit-Celsius table */ int main() { int fahr; for (fahr = 300; fahr >= 0; fahr = fahr - 20) printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32)); return 0; } Answer to Exercise 1-6 Verify that the expression getchar() != EOF is 0 or 1. /* This program prompts for input, and then captures a character * from the keyboard. If EOF is signalled (typically through a * control-D or control-Z character, though not necessarily), * the program prints 0. Otherwise, it prints 1. * * If your input stream is buffered (and it probably is), then 7
分享到:
收藏