Answers to Chapter 2 Review Questions ------------------------------------- 3. #include 4. #include "graphics.h" 5. main() 6. \n is a control character (called "newline") that causes the cursor to move to the beginning of the next line. It is ordinarily not used with prompt messages so that the cursor will remain on the same line as the message until the user types something in and hits RETURN. 8. int voteCount1, voteCount2; double x, y, z; 11. %d is used to print out the value of an integer variable, while %g is used to print out the value of a floating-point variable (which can be declared either as type "double" or type "float"). 15. The legal integer constants are: (a), (b), (e), and (i). The legal floating-point constants are: (d), (f), (h), (j), and (k). Note: (k) is written in scientific notation, but it is still a floating- point value. (c) is not a constant, but it is a valid expression. (g) is illegal because commas are not allowed in integers. (l) is illegal because scientific notation uses either "e" or "E" -- not "X". 16. (a) 6.02252E+23 (b) 2.997925E+10 (c) 5.29167E-9 (d) 3.1415926535E+0 17. The legal variable names are: (a), (b), (c), (f), (h), (k), and (l). Note: (e) is illegal because "short" is a reserved word in C. 18. Nothing. 19. (a) integer: 5 (b) integer: 3 (c) floating-point: 3.8 (d) floating-point: 18.0 (e) integer: 4 (f) integer: 2 20. The value of k will be 3 after executing the statement k = 3.14159; and its value will be 2 after executing the statement k = 2.71828; 21. The unary minus operator - is used to negate a single value, while the binary subtraction operator - is used to subtract one value from another. Unary minus is always performed before binary subtraction. 22. (a) 4 (b) 2 (c) 42 (d) 42 23. To explicitly convert between types, use a type cast operator, which is a type name in parentheses. Example: (int) (x / 3.14) converts the floating-point result of dividing x by 3.14 to an integer value.