Arithmetic Operations Flashcards

All 6 cards in this deck

What does the arithmetic operator MOD return?

e.g. 11 MOD 3

The remainder after integer division.
11 MOD 3 = 22

What does the arithmetic operator DIV return?

e.g. 11 DIV 3

The whole-number part of a division (remainder discarded).
11 DIV 3 = 33

True or false? The / operator always gives a whole-number answer.

False. / is real division and can give a decimal result, e.g. 7 / 2 = 3.5. DIV gives the whole-number part, e.g. 7 DIV 2 = 3.

True or false? In x ← 5 + 2 * 3, the multiplication is done before the addition.

True. Normal arithmetic precedence applies, so x is 11.

True or false? In IF total + 5 > 20 THEN, the comparison > is checked before the addition.

False. Arithmetic is done first, so total + 5 is worked out and then compared with 20.

How can MOD be used to test whether a whole number is even?

e.g. a number stored in n

n MOD 2 = 0 is true when n is even, because an even number leaves no remainder when divided by 2.