【正文】
%d:%d, amp。}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(The reversal is: %d%d%d\n, n % 10, (n / 10) % 10, n / 100)。 scanf(%d, amp。}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。 /* 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)。 printf(Item number: %d\n, item)。 printf(Group identifier: %d\n, group)。check_digit)。publisher, amp。prefix, amp。 printf(Enter ISBN: )。}3. [was 6。 printf(You entered the date %d%.2d%.2d\n, year, month, day)。day, amp。 scanf(%d/%d/%d, amp。 modified] include int main(void){ int month, day, year。 (d) printf(%, x)。 (b) printf(%, x)。 return 0。original_amount)。 printf(Enter an amount: )。 return 0。 amount_with_tax = original_amount * 。 scanf(%f, amp。 modified]include int main(void){ float original_amount, amount_with_tax。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 。 return 0。 printf(Value of y: %g\n, y)。 printf(Value of k: %d\n, k)。 printf(Value of i: %d\n, i)。s one possible program:include int main(void){ int i, j, k。 return 0。 printf(Volume (cubic inches): %d\n, volume)。 volume = height * length * width。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。 printf(Dimensions: %dx%dx%d\n, length, width, height)。 printf(Dimensional weight (pounds): %d\n, (volume + 165) / 166)。}4. [was 6] Here39。 float x, y, z。 printf(Value of j: %d\n, j)。 printf(Value of x: %g\n, x)。 printf(Value of z: %g\n, z)。}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。. Answers to Selected Programming Projects4. [was 8。 printf(Enter an amount: )。original_amount)。 printf(With tax added: $%.2f\n, amount_with_tax)。}The amount_with_tax variable is unnecessary. If we remove it, the program is slightly shorter:include int main(void){ float original_amount。 scanf(%f, amp。 printf(With tax added: $%.2f\n, original_amount * )。}Chapter 3Answers to Selected Exercises2. [was 2] (a) printf(%, x)。 (c) 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。 printf(Enter a date (mm/dd/yyyy): )。month, amp。year)。 return 0。 modified] include int main(void){ int prefix, group, publisher, item, check_digit。 scanf(%d%d%d%d%d, amp。group, amp。item, amp。 printf(GS1 prefix: %d\n, prefix)。 printf(Publisher code: %d\n, publisher)。 printf(Check digit: %d\n, check_digit)。 */ return 0。 printf(Enter a threedigit number: )。n)。 return 0。 printf(Enter a 24hour time: )。hours, amp。 printf(Equivalent 12hour time: )。 else if (hours 12) printf(%d:%.2d AM\n, hours, minutes)。 else printf(%d:%.2d PM\n, hours 12, minutes)。}4. [was 8。 printf(Enter a wind speed in knots: )。speed)。 else if (speed = 3) printf(Light air\n)。 else if (speed = 47) printf(Gale\n)。 else printf(Hurricane\n)。}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。 scanf(%1d, amp。 printf(Enter first group of five digits: )。i1, amp。i3, amp。i5)。 scanf(%1d%1d%1d%1d%1d, amp。j2, amp。j4, amp。 printf(Enter the last (single) digit: )。check_digit)。 second_sum = i1 + i3 + i5 + j2 + j4。 if (check_digit == 9 ((total 1) % 10)) printf(VALID\n)。 return 0。 printf(Enter numerical grade: )。grade)。 return 0。 break。 break。 break。 break。 break。}Chapter 6Answers to Selected Exercises4. [was 10] (c) is not equivalent to (a) and (b), because i is incremented before the loop body is executed. 10. [was 12] Consider the following while loop: while (…) { … continue。 … loop_end: 。 d * d = n。The if statement that follows the loop will need to be modified as well:if (d * d = n) printf(%d is divisible by %d\n, n, d)。14. [was 16] The problem is the semicolon at the end of the first line. If we remove it, the statement is now correct: if (n % 2 == 0) printf(n is even\n)。 pr