Integer CS Thinking Example 1
Follow the full solution, then compare it with the other examples linked below.
Example 1
easyWhat is the result of integer division and ? Explain the difference from regular division.
Solution
- 1 Step 1: Regular division: .
- 2 Step 2: Integer division (floor): (discard the decimal part).
- 3 Step 3: Modulo: (the remainder after dividing 17 by 5).
Answer
DIV: 3, MOD: 2. Regular division gives 3.4.
Integer division returns the whole-number quotient, while modulo returns the remainder. Together they fully describe the result: .
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 2 medium
A program stores a student's age as an integer. Why would an integer be more appropriate than a floa
Example 3 easyWhat are the results of: (a) 25 MOD 7, (b) 100 DIV 3, (c) 8 MOD 2?
Example 4 mediumA vending machine program stores the price as 175 (meaning $1.75 in cents). A customer inserts 200 c