Unable to open this exercise
Common exam pitfall
Students often check MOD 1 instead of MOD 2 to test for even numbers.
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
Operator | Full Name | Purpose | Example ( |
|---|---|---|---|
| Real Division | Divides and returns a floating-point |
|
| Integer Division | Returns the integer quotient, discarding any fractional remainder. |
|
| Modulo Division | Returns the remainder left over after integer division. |
|
Fundamental Mathematical Identity:
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)
AI Socratic Tutor
Need guidance? Ask a question or use the hint below.
AI Socratic Tutor is an All-Access Benefit
Unlock step-by-step Socratic hints, algorithm trace table walkthroughs, and error diagnostics for every Cambridge exercise.
You're chatting with an AI tutor, not a person. AI can make mistakes, so double-check its answers.
Exam-Style Question: Even or Odd Number Test with MOD
Complete the selection condition to determine if an integer variable N is an even number:
IF N [Space 1] 2 = [Space 2] THEN
OUTPUT "Even"
ELSE
OUTPUT "Odd"
ENDIF
Interactive exercises for Module 2 and beyond require an active plan.