Which expression gives 4?
Refer to the insert for the list of pseudocode functions and operators.
Which of these expressions evaluates to the INTEGER value 4?
A 17 MOD 4
B INT(17 / 4)
C 17 / 4
D NUM_TO_STR(17 DIV 4)
[1]
- 1
Evaluate each option.
- A
MODgives the remainder: 17 = 4 × 4 + 1, so the value is 1. - C
/is ordinary division and gives the REAL value 4.25. - D
17 DIV 4is 4, butNUM_TO_STRturns it into the STRING "4", not an INTEGER.
- A
- 2
B
17 / 4is 4.25, andINTreturns the integer part, 4, of type INTEGER. Answer B (1).
Answer
B (INT(17 / 4))
Examiner tip
Examiner tip: DIV and INT( / ) give the same whole-number quotient for positive values. MOD gives what is left over. Learn the insert examples 10 DIV 3 = 3 and 10 MOD 3 = 1.
Common mistake: choosing D. The question asks for an INTEGER, and anything returned by NUM_TO_STR is a string, even when it looks like a number.