4. Variables
Exercises
-
Execute by hand the program given in this chapter that calculates the area of a rectangle. Standard input should have the following data:
11 14
Do it step by step, using a paper, a pencil, and an eraser. On completing the execution, you should end up with a paper looking exactly like this:STDIN
STDOUT
MEMORY
11 14
Type in the length of side a:
Type in the length of side b:
The area of the rectangle is 154
a
11
b
14
A
154
- Write a program that reads in (from standard input) a price of an item of clothing in dollars and then writes out to standard output how much the price would be if that item was at 10% discount. Note that ten percent is equal to 0.1; furthermore, 10% of a value is the same as multiplying that value by 0.1.
- Write a program that reads in two numbers from standard input: the price of sneakers before discount, and discounted price. The program should output the percentage the sneakers were discounted.
- Write a program that reads in (from standard input) the length of a movie in hours and minutes. The program should calculate and write out (to standard output) the length of the movie in minutes.
- Write a program that reads in (from standard input) the length of a movie in hours, minutes, and seconds. The program should calculate and write out (to standard output) the length of the movie in seconds.