Even Book Problem Answers - C PROGRAMMING A Modern Approach...

This preview shows pages 1–6. Sign up to view the full content.

C PROGRAMMING A Modern Approach Answers to Even-Numbered Exercises Susan A. Cole K. N. King New York · London

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
All rights reserved. 500 Fifth Avenue, New York, N.Y. 10110 http://www.wwnorton.com 10 Coptic Street, London WC1A 1PU Last updated: August 19, 1996 Send corrections to [email protected]
2. (a) The program contains one directive ( #include ) and four statements (three calls of printf and one return ). (b) Parkinson's Law: Work expands so as to fill the time available for its completion. 4. #include <stdio.h> main() { int height = 8, length = 12, width = 10, volume; volume = height * length * width; printf("Dimensions: %dx%dx%d\n", length, width, height); printf("Volume (cubic inches): %d\n", volume); printf("Dimensional weight (pounds): %d\n", (volume + 165) / 166); return 0; } 6. Here's one possible program: #include <stdio.h> main() { 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 Borland C++ 5.0 and then executed, this program produced the following output: Value of i: 0 Value of j: 0 Value of k: 4223020 Value of x: 1.4013e-45 Value of y: 5.92554e-39 Value of z: 5.90822e-39 The values printed depend on many factors, so the chance that you'll get exactly these numbers is small. 2 C Fundamentals

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CHAPTER 2 C FUNDAMENTALS 4 8. #include <stdio.h> main() { float original_amount, amount_with_tax; printf("Enter a dollar amount: "); scanf("%f", &original_amount); amount_with_tax = original_amount * 1.05; printf("With 5%% tax added: %.2f\n", amount_with_tax); return 0; } The amount_with_tax variable is unnecessary. If we remove it, the program is slightly shorter: #include <stdio.h> main() { float original_amount; printf("Enter a dollar amount: "); scanf("%f", &original_amount); printf("With 5% tax added: %.2f\n", original_amount * 1.05); return 0; } 10. (a) is not legal because 100_bottles begins with a digit. 12. There are 14 tokens: a , = , ( , 3 , * , q , - , p , * , p , ) , / , 3 , and ; .
2. (a) printf("%-8.1e", x); (b) printf("%10.6e", x); (c) printf("%-8.3f", x); (d) printf("%6.0f", x); 4. #include <stdio.h> main() { int month, day, year; printf("Enter a date (mm/dd/yy): "); scanf("%d/%d/%d", &month, &day, &year); printf("You entered the date %.2d%.2d%.2d\n", year, month, day); return 0; } 6. #include <stdio.h> main() { int language, publisher, book_number, check_digit; printf("Enter ISBN: "); scanf("%d-%d-%d-%d", &language, &publisher, &book_number, &check_digit); printf("Language: %d\n", language); printf("Publisher: %d\n", publisher); printf("Book number: %d\n", book_number); printf("Check digit: %d\n", check_digit); /* The four printf calls can be combined as follows: printf("Language: %d\nPublisher: %d\nBook number: %d\nCheck digit: %d\n",

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/22/2008 for the course EE 312 taught by Professor Shafer during the Spring '08 term at University of Texas at Austin.

Page1 / 71

Even Book Problem Answers - C PROGRAMMING A Modern Approach...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online