Integer CS Thinking Example 1

Follow the full solution, then compare it with the other examples linked below.

Example 1

easy
What is the result of integer division 17÷517 \div 5 and 17mod517 \mod 5? Explain the difference from regular division.

Solution

  1. 1
    Step 1: Regular division: 17÷5=3.417 \div 5 = 3.4.
  2. 2
    Step 2: Integer division (floor): 17 DIV 5=317 \text{ DIV } 5 = 3 (discard the decimal part).
  3. 3
    Step 3: Modulo: 17 MOD 5=217 \text{ MOD } 5 = 2 (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: 17=5×3+217 = 5 \times 3 + 2.

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