[SOLVED] SOLVED: Chapter 3 Solutions to exercises from the book C Primer Plus by Stephen Prata

49.99 $

Programming resource
Digital learning resource
Category:
Practical programming resource
Suitable for guided study and reference
Tutor guidance available when needed

Description

5/5 - (2 votes)

Exercise1.

Find out what your system does with integer overflow, floating-point overflow,
and floating point underflow by using the experimental approach; that is,
write programs that have these problems.

Exercise 2:
Write a program that asks you to enter an ASCII code value, such as 66, and
then prints the character having that ASCII code.

Exercise 3:
Write a program that sounds an alert and then prints the following text: Startled by the sudden sound, Sally shouted,
“By the Great Pumpkin, what was that!”

Exercise 4:
Write a program that reads in a floating-point number and prints it first in decimal-point notation, then in exponential notation, and then, if your system supports it, p notation. Have the output use the following format (the actual number of digits displayed for the exponent depends on the system):

Enter a floating-point value: 64.25
fixed-point notation: 64.250000
exponential notation: 6.425000e+01
p notation: 0x1.01p+6

Exercise 5

There are approximately 3.156 × 10^7 seconds in a year. Write a program that requests your age in years and then displays the equivalent number of seconds.

Exercise 6:

The mass of a single molecule of water is about 3.0×10^-23 grams. A quart of
water is about 950 grams. Write a program that requests an amount of water,
in quarts, and displays the number of water molecules in that amount.

Exercise 7:

There are 2.54 centimeters to the inch. Write a program that asks you to enter
your height in inches and then displays your height in centimeters. Or, if you
prefer, ask for the height in centimeters and convert that to inches.

Exercise 8:

In the U.S. system of volume measurements, a pint is 2 cups, a cup is 8 ounces,
an ounce is 2 tablespoons, and a tablespoon is 3 teaspoons. Write a program
that requests a volume in cups and that displays the equivalent volumes in
pints, ounces, tablespoons, and teaspoons. Why does a floating-point type make
more sense for this application than an integer type?

Resource details

Understand the Task Before You Use the Resource

Review the requirements, identify the programming concepts involved, study the implementation and test your understanding with your own examples and modifications.