Chapter 22.1, 2.2, 2.3 Answers
Answers to the odd-numbered questions are in the back of the text book.
2.1-2 The standard identifiers have particular meanings in C programs. Redefining standard identifiers for use as variables may mean that C cant use them for their original purpose. Your program may not work as intended. The C compiler will not let you use reserved words as identifiers; thats why the words are called reserved.
2.1-4 Using the word PI is clearer and less subject to typing error than using the string of digits. Defining it once, you can change the definition in that one place to add or remove precision and the change will be used everywhere that PI appears; you dont have to make the change in more than one place. This makes your program easier to modify and maintain. PI is a constant that doesnt change during the execution of the program, so it doesnt need to be a variable.
2.2-2 int: 15, -999; double: 25.123, 15.0, 32e-4, .123; char: x, *The others are not valid C language int, double, or char constants.
2.2-P1 #define PI 3.14159
double radius, area, circumf;
2.3-2 Before: undefined. After execution: m=10, n=21.
2.3-4 Change the \n at the end of the sentence to be \n\n.
2.3-P1 printf(Enter three integers: );
scanf(%d%d%d, &first, &second, &third);
2.3-P2-a printf(The value of x is %f\n, x);
2.3-P2-b printf(The area of a circle with radius %f is %f.\n, radius, area);
#define PI 3.14159 /* sufficient accuracy for float math */
float radius; /* 6-7 decimal digits; 10E-38 to 10E38 */
printf(Enter the radius of the circle: );
printf(The area of the circle with radius %f is %f.\n,
radius, PI * radius * radius );
return(0); /* the operating system return code */