Chapter 6

  1. 2, 7, 70, 64, 8, 2

  2. It would produce the following output:

    36 18  9  4  2  1
    
    1. x > 5

    2. scanf("%lf",&x) != 1

    3. x == 5

    1. scanf("%d", &x) == 1

    2. x != 5

    3. x >= 20

  3. Line 4: Should be list[10].

    Line 6: Commas should be semicolons.

    Line 6: Range for i should be from 0 to 9, not 1 to 10.

    Line 9: Commas should be semicolons.

    Line 9: >= should be <=. Otherwise, when i is 1, the loop never ends.

    Line 10: There should be another closing brace between lines 9 and 10. One brace closes the compound statement, and one closes the program. In between should be a return 0; line.

    Here's a corrected version:

     #include <stdio.h〉 int main(void) { /* line 3 */ int i, j, list[10]; /* line 4 */ for (i = 0; i < 10; i++) /* line 6 */ { /* line 7 */ list[i] = 2*i + 3; /* line 8 */ for (j = 1; ...

Get C Primer Plus®, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.