【正文】
Chapter 2Answers to Selected Exercises2. [was 2] (a) The program contains one directive (include) and four statements (three calls of printf and one return).(b) Parkinson39。s Law:Work expands so as to fill the timeavailable for its pletion.3. [was 4]include int main(void){ int height = 8, length = 12, width = 10, volume。 volume = height * length * width。 printf(Dimensions: %dx%dx%d\n, length, width, height)。 printf(Volume (cubic inches): %d\n, volume)。 printf(Dimensional weight (pounds): %d\n, (volume + 165) / 166)。 return 0。}4. [was 6] Here39。s one possible program:include int main(void){ int i, j, k。 float x, y, z。 printf(Value of i: %d\n, i)。 printf(Value of j: %d\n, j)。 printf(Value of k: %d\n, k)。 printf(Value of x: %g\n, x)。 printf(Value of y: %g\n, y)。 printf(Value of z: %g\n, z)。 return 0。}When piled using GCC and then executed, this program produced the following output:Value of i: 5618848Value of j: 0Value of k: 6844404Value of x: Value of y: Value of z: The values printed depend on many factors, so the chance that you39。ll get exactly these numbers is small.5. [was 10] (a) is not legal because 100_bottles begins with a digit.8. [was 12] There are 14 tokens: a, =, (, 3, *, q, , p, *, p, ), /, 3, and 。. Answers to Selected Programming Projects4. [was 8。 modified]include int main(void){ float original_amount, amount_with_tax。 printf(Enter an amount: )。 scanf(%f, amp。original_amount)。 amount_with_tax = original_amount * 。 printf(With tax added: $%.2f\n, amount_with_tax)。 return 0。}The amount_with_tax variable is unnecessary. If we remove it, the program is slightly shorter:include int main(void){ float original_amount。 printf(Enter an amount: )。 scanf(%f, amp。original_amount)。 printf(With tax added: $%.2f\n, original_amount * )。 return 0。}Chapter 3Answers to Selected Exercises2. [was 2] (a) printf(%, x)。 (b) printf(%, x)。 (c) printf(%, x)。 (d) printf(%, x)。 5. [was 8] The values of x, i, and y will be , 45, and .6, respectively.Answers to Selected Programming Projects1. [was 4。 modified] include int main(void){ int month, day, year。 printf(Enter a date (mm/dd/yyyy): )。 scanf(%d/%d/%d, amp。month, amp。day, amp。year)。 printf(You entered the date %d%.2d%.2d\n, year, month, day)。 return 0。}3. [was 6。 modified] include int main(void){ int prefix, group, publisher, item, check_digit。 printf(Enter ISBN: )。 scanf(%d%d%d%d%d, amp。prefix, amp。group, amp。publisher, amp。item, amp。check_digit)。 printf(GS1 prefix: %d\n, prefix)。 printf(Group identifier: %d\n, group)。 printf(Publisher code: %d\n, publisher)。 printf(Item number: %d\n, item)。 printf(Check digit: %d\n, check_digit)。 /* The five printf calls can be bined as follows: printf(GS1 prefix: %d\nGroup identifier: %d\nPublisher code: %d\nItem number: %d\nCheck digit: %d\n, prefix, group, publisher, item, check_digit)。 */ return 0。}Chapter 4Answers to Selected Exercises2. [was 2] Not in C89. Suppose that i is 9 and j is 7. The value of (i)/j could be either –1 or –2, depending on the implementation. On the other hand, the value of (i/j) is always –1, regardless of the implementation. In C99, on the other hand, the value of (i)/j must be equal to the value of (i/j). 9. [was 6] (a) 63 8 (b) 3 2 1 (c) 2 1 3 (d) 0 0 0 13. [was 8] The expression ++i is equivalent to (i += 1). The value of both expressions is i after the increment has been performed. Answers to Selected Programming Projects2. [was 4] include int main(void){ int n。 printf(Enter a threedigit number: )。 scanf(%d, amp。n)。 printf(The reversal is: %d%d%d\n, n % 10, (n / 10) % 10, n / 100)。 return 0。}Chapter 5Answers to Selected Exercises2. [was 2] (a) 1 (b) 1 (c) 1 (d) 1 4. [was 4] (i j) (i j) 6. [was 12] Yes, the statement is legal. When n is equal to 5, it does nothing, since 5 is not equal to –9. 10. [was 16] The output is onetwosince there are no break statements after the cases. Answers to Selected Programming Projects2. [was 6] include int main(void){ int hours, minutes。 printf(Enter a 24hour time: )。 scanf(%d:%d, amp。hours, amp。minutes)。 printf(Equivalent 12hour time: )。 if (hours == 0) printf(12:%.2d AM\n, minutes)。 else if (hours 12) printf(%d:%.2d AM\n, hours, minutes)。 else if (hours == 12) printf(%d:%.2d PM\n, hours, minutes)。 else printf(%d:%.2d PM\n, hours 12, minutes)。 return 0。}4. [was 8。 modified] include int main(void){ int speed。 printf(Enter a wind speed in knots: )。 scanf(%d, amp。speed)。 if (speed 1) printf(Calm\n)。 else if (speed = 3) printf(Light air\n)。 else if (speed = 27) printf(Breeze\n)。 else if (speed = 47) printf(Gale\n)。 else if (speed = 63) printf(Storm\n)。 else printf(Hurricane\n)。 return 0。}6. [was 10] include int main(void){ int check_digit, d, i1, i2, i3, i4, i5, j1, j2, j3, j4, j5, first_sum, second_sum, total。 printf(Enter the first (single) digit: )。 scanf(%1d, amp。d)。 printf(Enter first group of five digits: )。 scanf(%1d%1d%1d%1d%1d, amp。i1, amp。i2, amp。i3, amp。i4, amp。i5)。 printf(Enter second group of five digits: )。 scanf(%1d%1d%1d%1d%1d, amp。j1, amp。j2, amp。j3, amp。j4, amp。j5)。 printf(Enter the last (single) digit: )。 scanf(%1d, amp。check_digit)。 first_sum = d + i2 + i4 + j1 + j3 + j5。 second_sum = i1 + i3 + i5 + j2 + j4。 total = 3 * first_sum + second_sum。 if (check_digit == 9 ((total 1) % 10)) printf(VALID\n)。 else printf(NOT VALID\n)。 return 0。}10. [was 14] include int main(void){ int grade。 printf(Enter numerical grade: )。 scanf(%d, amp。grade)。 if