# Integer Division: DIV (Quotient) & MOD (Remainder)

- **Track:** Cambridge IGCSE™ Computer Science (0478 / 0984) (CAMBRIDGE IGCSE 0478)
- **Module:** Section 8: Programming Concepts & File Handling
- **Estimated Duration:** 10 minutes
- **Access:** Open Theory (All-Access for Interactive IDE &amp; Autotests)

---

## Theory & Conceptual Background

In computer science, integer arithmetic frequently requires decomposing divisions into two distinct components: the whole number of times a divisor fits into a dividend, and the leftover remainder.

1. The Distinction Between /, DIV, and MOD

  
    OperatorFull NamePurposeExample (17 and 5)
    /Real DivisionDivides and returns a floating-point REAL quotient with decimals.17 / 5 = 3.4DIVInteger DivisionReturns the integer quotient, discarding any fractional remainder.17 DIV 5 = 3MODModulo DivisionReturns the remainder left over after integer division.17 MOD 5 = 2
  

Fundamental Mathematical Identity:
$$\text{Dividend} = (\text{Dividend} \text{ DIV } \text{Divisor}) \times \text{Divisor} + (\text{Dividend} \text{ MOD } \text{Divisor})$$
$$17 = (3 \times 5) + 2$$

2. Common Exam Applications in Cambridge Paper 2
1. Unit & Time Conversions
Transforming flat units (e.g. seconds, cents, grams) into compound units (e.g. hours/minutes/seconds, dollars/cents, kilograms/grams):
Hours <- TotalSeconds DIV 3600
RemainingSeconds <- TotalSeconds MOD 3600
Minutes <- RemainingSeconds DIV 60
Seconds <- RemainingSeconds MOD 60
2. Odd and Even Number Determination
Any integer N is even if and only if dividing by 2 leaves zero remainder:
IF Number MOD 2 = 0 THEN
    OUTPUT "Number is Even"
ELSE
    OUTPUT "Number is Odd"
ENDIF
3. Extracting and Stripping Digits
Extract units digit: Units <- Value MOD 10 (e.g. 247 MOD 10 = 7)Strip units digit: Value <- Value DIV 10 (e.g. 247 DIV 10 = 24)

---

## Interactive Exercises & Autotest Specifications

### Exercise 1: Exam-Style Check: Distinguish DIV and MOD Operations (Multiple choice, 25 XP)

**Instructions:**
What are the evaluated results of `29 DIV 6` and `29 MOD 6` in Cambridge pseudocode?

**Options:**
- **A**: 29 DIV 6 = 4 and 29 MOD 6 = 5
- **B**: 29 DIV 6 = 5 and 29 MOD 6 = 4
- **C**: 29 DIV 6 = 4.83 and 29 MOD 6 = 0.83
- **D**: 29 DIV 6 = 4 and 29 MOD 6 = 0


**Autotest Expectations:**
- **DIV and MOD values correctly calculated**: `selection_match` -> Expected: `opt_correct`

### Exercise 2: Exam-Style Question: Even or Odd Number Test with MOD (Fill in blank, 35 XP)

**Instructions:**
Complete the selection condition to determine if an integer variable `N` is an even number:

```pseudocode
IF N [blank_1] 2 = [blank_2] THEN
    OUTPUT "Even"
ELSE
    OUTPUT "Odd"
ENDIF
```


**Starter Code:**
```text
{"template":"IF N [blank_1] 2 = [blank_2] THEN\n    OUTPUT \"Even\"\nELSE\n    OUTPUT \"Odd\"\nENDIF","word_bank":["MOD","DIV","/","0","1","2"],"prompt":"Exam-Style Question: Even or Odd Number Test with MOD","blanks":[{"id":"blank_1"},{"id":"blank_2"}]}
```

**Autotest Expectations:**
- **Operator is MOD**: `text_exact` -> Expected: `MOD`
- **Remainder is 0**: `text_exact` -> Expected: `0`

### Exercise 3: Independent Practice: Elapsed time (Pseudocode, 30 XP)

**Instructions:**
Read a non-negative integer number of seconds. Output the whole hours, remaining minutes and remaining seconds, each on a separate line.

Write a complete program. Read inputs in the stated order. Output only the requested results, one per line, without input prompts. Test with your own values before submitting.


**Starter Code:**
```text
// Plan your solution, then write your program.

```

**Autotest Expectations:**
- **Mixed units**: `test_case` -> Expected: `{&quot;inputs&quot;:[3661],&quot;output&quot;:&quot;1\n1\n1&quot;}`
- **Exactly two hours**: `test_case` -> Expected: `{&quot;inputs&quot;:[7200],&quot;output&quot;:&quot;2\n0\n0&quot;}`
- **Under one minute**: `test_case` -> Expected: `{&quot;inputs&quot;:[59],&quot;output&quot;:&quot;0\n0\n59&quot;}`
- **Zero**: `test_case` -> Expected: `{&quot;inputs&quot;:[0],&quot;output&quot;:&quot;0\n0\n0&quot;}`

