Cambridge pseudocode

What DIV Does in Pseudocode

DIV counts how many whole times the second number fits into the first, then drops the fraction. It does not round. 10 DIV 3 is 3, because 3 fits three times and the leftover 1 is not enough for a fourth.

How it works

DIV and MOD rebuild the original number

MOD is that leftover. Together they are a pair: take the whole part, multiply back, add the remainder, and you return to the number you started with. Ordinary / keeps the fraction, so 10 / 4 is 2.5. Write DIV between the operands in an exam answer. DIV(10, 3) also runs here. The infix form is the one mark schemes use.

OUTPUT 10 DIV 3
OUTPUT 10 MOD 3
OUTPUT (10 DIV 3) * 3 + (10 MOD 3)
OUTPUT -7 DIV 3
Output
3
1
10
-2

-7 DIV 3 is -2, not -3. The fraction is cut off toward zero. -2.333 becomes -2. That is truncation, the same cut INT uses.

In Python

// floors. DIV does not.

For positive numbers, Python // matches DIV. For negatives it does not. // rounds toward negative infinity, so -7 // 3 is -3. This site’s Python converter emits a small DIV function for that reason, instead of trusting //.

Python
print(10 // 3)   # 3
print(-7 // 3)   # -3, not the Cambridge result
print(-7 / 3)    # -2.333...

Beyond the exam

Toward zero, or toward negative infinity

Integer division has two honest answers once a sign appears, and languages picked differently. Cambridge, C, Java and JavaScript cut toward zero. Python and the older maths convention of the floor function go down. The remainder has to follow the same choice, or the rebuild identity breaks. If a question stays with positive integers, both languages agree and you will not see the split.

Run the example in the pseudocode compiler online, or read the matching section of the Cambridge pseudocode guide.