Skip to main content

Exercises 3.16 Exercises

Remember to work one step at a time! If you are feeling stuck, try to think of the smallest bit of work you can try to do in order to get one step closer to your goal. Then just worry about that one step of work.

1.

The code below reads in two integers a and b. Add code to print their sum, product, the value of a divided by b, the remainder after a is divided by b, and the value of \(2a + 3b\text{.}\) Each value should go on its own line. For example, given the inputs 5 3, you should print:
8
15
1
2
19

2.

The code declares an integer a and b and reads in a value for a. Later on, the code prints out the values of a, b, and c.
Your task is to add code in between those parts that:
  • Sets b to have the value that was read in for a.
  • Increases a by 10.
  • Declares c and sets it to have the value of a (new value) plus b.

3.

The code below reads in a number of cents. Print that amount in dollars and cents (separated by a space with no other characters). For example, given 182 you should print 1 82. Given 405 you should print 4 5.
Hint.
This is like the Time Case Study. Use a combination of division and remainder to get the two values.

4.

The code below reads in a number of cents. Print out the number of quarters, dimes, nickles, and pennies required to make that amount. Separate each coin value by a space and do not print any other characters. For example, given 7 you should print 0 0 1 2 indicating 0 quarters, 0 dimes, 1 nickel, and 2 pennies. Given 143, you should print 5 1 1 3 indicating 5 quarters, 1 dime, 1 nickel, and 3 pennies.
Hint.
This is like the Time Case Study. Use a combination of division and remainder. Work on one coin type at a time and make sure to progress in a consistent direction (either increasing or decreasing value).
You have attempted of activities on this page.