-- Programming Language Books and Training

 C C++ Java

Books by K. N. King

Books by K. N. King
Short courses
Recommended books
Recommended links

C Programming: A Modern Approach (Second Edition)

Chapter 3

Answers to Selected Exercises

2. [was #2]

(a) printf("%-8.1e", x);
(b) printf("%10.6e", x);
(c) printf("%-8.3f", x);
(d) printf("%6.0f", x);

5. [was #8] The values of x, i, and y will be 12.3, 45, and .6, respectively.

Answers to Selected Programming Projects

1. [was #4; modified]

#include <stdio.h>

int main(void)
  int month, day, year;

  printf("Enter a date (mm/dd/yyyy): ");
  scanf("%d/%d/%d", &month, &day, &year);
  printf("You entered the date %d%.2d%.2d\n", year, month, day);

  return 0;

3. [was #6; modified]

#include <stdio.h>

int main(void)
  int prefix, group, publisher, item, check_digit;

  printf("Enter ISBN: ");
  scanf("%d-%d-%d-%d-%d", &prefix, &group, &publisher, &item, &check_digit);

  printf("GS1 prefix: %d\n", prefix);
  printf("Group identifier: %d\n", group);
  printf("Publisher code: %d\n", publisher);
  printf("Item number: %d\n", item);
  printf("Check digit: %d\n", check_digit);

  /* The five printf calls can be combined as follows:

     printf("GS1 prefix: %d\nGroup identifier: %d\nPublisher code: %d\nItem number: %d\nCheck digit: %d\n",
            prefix, group, publisher, item, check_digit);

  return 0;

Copyright © 2008, 1996 W. W. Norton & Company, Inc. All rights reserved.