Integer CS Thinking Example 3
Follow the full solution, then compare it with the other examples linked below.
Example 3
easyWhat are the results of: (a) 25 MOD 7, (b) 100 DIV 3, (c) 8 MOD 2?
Solution
- 1 Step 1: (a) 25 รท 7 = 3 remainder 4, so 25 MOD 7 = 4. (b) 100 รท 3 = 33 remainder 1, so 100 DIV 3 = 33.
- 2 Step 2: (c) 8 รท 2 = 4 remainder 0, so 8 MOD 2 = 0 (8 is even).
Answer
(a) 4, (b) 33, (c) 0.
MOD = 0 tells us a number is evenly divisible. This is commonly used to check if a number is even (n MOD 2 == 0) or to cycle through values.
About Integer
A data type that represents whole numbers (positive, negative, or zero) without decimal points. Integers are stored exactly in memory and support arithmetic operations like addition, subtraction, multiplication, and integer division.
Learn more about Integer โMore Integer Examples
Example 1 easy
What is the result of integer division [formula] and [formula]? Explain the difference from regular
Example 2 mediumA program stores a student's age as an integer. Why would an integer be more appropriate than a floa
Example 4 mediumA vending machine program stores the price as 175 (meaning $1.75 in cents). A customer inserts 200 c