|
|
|
Chapter 2Answers to Selected Exercises
2. [was #2] (a) The program contains one directive ( (b) Parkinson's Law: Work expands so as to fill the time available for its completion. 3. [was #4]
4. [was #6] Here's one possible program: #include <stdio.h> 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 compiled using GCC and then executed, this program produced the following output: Value of i: 5618848 Value of j: 0 Value of k: 6844404 Value of x: 3.98979e-34 Value of y: 9.59105e-39 Value of z: 9.59105e-39 The values printed depend on many factors, so the chance that you'll get exactly these numbers is small.
5. [was #10] (a) is not legal because
8. [was #12] There are 14 tokens: Answers to Selected Programming Projects4. [was #8; modified] #include <stdio.h> int main(void) { float original_amount, amount_with_tax; printf("Enter an amount: "); scanf("%f", &original_amount); amount_with_tax = original_amount * 1.05f; printf("With tax added: $%.2f\n", amount_with_tax); return 0; }
The #include <stdio.h> int main(void) { float original_amount; printf("Enter an amount: "); scanf("%f", &original_amount); printf("With tax added: $%.2f\n", original_amount * 1.05f); return 0; } Copyright © 2008, 1996 W. W. Norton & Company, Inc. All rights reserved. |