Expressions and Arithmetic Operators
Read this chapter, which discusses arithmetic operations in greater detail along with solving expressions with mixed data types.
16. Practice with Remainder Operator
Answer:
- Number of dollar bills is
372 / 100 == 3 - Left over pennies is
372 % 100 == 72
Practice with Remainder Operator
For positive integers, INT % X means to fit as many X as you can into INT, and then the left over amount is the value of the expression. Try that with the following:
| Expression | Result | Expression | Result |
|---|---|---|---|
| 7 3 | 7 5 | ||
| 10 5 | 10 6 | ||
| 129 100 | 1999 100 | ||
| 17 2 | 18 2 |
Question 16:
If
Xis odd, what isX % 2?