CS8: Arithmetic and Relational Operations
Master arithmetic operators including DIV and MOD, relational operators for comparison, and the order of operations in pseudo-code.
Master arithmetic operators including DIV and MOD, relational operators for comparison, and the order of operations in pseudo-code.
| Operator | Symbol | Description | Example | Result |
|---|---|---|---|---|
| Addition | + | Add two values | 5 + 3 | 8 |
| Subtraction | - | Subtract second from first | 10 - 4 | 6 |
| Multiplication | * | Multiply two values | 6 * 7 | 42 |
| Real division | / | Divide, returns decimal | 7 / 2 | 3.5 |
| Integer division | DIV | Divide, returns whole number only | 7 DIV 2 | 3 |
| Modulo (remainder) | MOD | Returns the remainder after division | 7 MOD 2 | 1 |
| Exponent | ^ | Raises to a power | 2 ^ 3 | 8 |
| Expression | Result | Explanation |
|---|---|---|
| 10 DIV 3 | 3 | 10 / 3 = 3.33..., whole number part = 3 |
| 10 MOD 3 | 1 | Remainder when 10 is divided by 3 |
| 20 DIV 4 | 5 | 20 / 4 = 5 exactly, no remainder |
| 20 MOD 4 | 0 | No remainder |
| 15 DIV 4 | 3 | 15 / 4 = 3.75, whole number part = 3 |
| 15 MOD 4 | 3 | Remainder = 15 - (4 * 3) = 15 - 12 = 3 |
INPUT number
IF number MOD 2 = 0 THEN
OUTPUT number, " is even"
ELSE
OUTPUT number, " is odd"
ENDIF
| Operator | Symbol | Meaning | Example | Result |
|---|---|---|---|---|
| Equal to | = | Both values are the same | 5 = 5 | TRUE |
| Not equal to | <> | Values are different | 5 <> 3 | TRUE |
| Less than | < | First value is smaller | 3 < 5 | TRUE |
| Greater than | > | First value is larger | 7 > 4 | TRUE |
| Less than or equal to | <= | First value is smaller or equal | 5 <= 5 | TRUE |
| Greater than or equal to | >= | First value is larger or equal | 6 >= 3 | TRUE |
IF age >= 18 THEN
OUTPUT "Adult"
ENDIF
WHILE attempts < 3
INPUT "Try again: ", guess
attempts ← attempts + 1
ENDWHILE
IF password = "secret" THEN
OUTPUT "Access granted"
ENDIF
3 + 4 * 2 = 3 + 8 = 11 (multiplication before addition) (3 + 4) * 2 = 7 * 2 = 14 (brackets first) 10 - 3 - 2 = 7 - 2 = 5 (left to right) 2 ^ 3 ^ 2 = 8 ^ 2 = 64 (left to right for exponents) 10 DIV 3 + 1 = 3 + 1 = 4 (DIV before addition) 10 + 3 MOD 2 = 10 + 1 = 11 (MOD before addition)
result ← 2 + 3 * 4 ^ 2 - 1
Step 1: 4 ^ 2 = 16
Step 2: 3 * 16 = 48
Step 3: 2 + 48 = 50
Step 4: 50 - 1 = 49
result = 49
| Mistake | Why It's Wrong | How to Fix It |
|---|---|---|
| Confusing / and DIV | / returns a decimal, DIV returns an integer | Use / for real results, DIV for whole number results |
| Using = for assignment | In pseudo-code = means "equal to" | Use ← for assignment |
| Forgetting brackets | Average of 3+4+5 is not 3+4+5/3 | Use (3+4+5)/3 = 4, not 3+4+5/3 = 8.67 |
| MOD with negative numbers | Different languages handle this differently | At GCSE, assume positive numbers only |
| Wrong order of operations | 2+3*4 = 14, not 20 | Use brackets to make your intention clear |
Q1: Evaluate: 17 DIV 5 and 17 MOD 5
Q2: Write pseudo-code that checks if a number is divisible by 3.
Q3: Evaluate step by step: 3 + 4 * 2 - 1
Q4: Write pseudo-code that takes a number of minutes and outputs the hours and remaining minutes.
Q5: What is the result of (10 + 5) / 3? What about 10 + 5 / 3?
INPUT number
IF number MOD 3 = 0 THEN
OUTPUT number, " is divisible by 3"
ELSE
OUTPUT number, " is not divisible by 3"
ENDIF
INPUT totalMinutes hours ← totalMinutes DIV 60 minutes ← totalMinutes MOD 60 OUTPUT hours, " hours and ", minutes, " minutes"
✗ Confusing = (assignment) with == (comparison) ✓ A single = assigns a value to a variable; == compares two values for equality. In pseudo-code, ← is assignment and = is comparison.
✗ Forgetting operator precedence — assuming left-to-right evaluation always applies ✓ BODMAS/BIDMAS rules apply: brackets first, then multiplication/division, then addition/subtraction. Use brackets to make order explicit.
✗ Using DIV when MOD is needed (or vice versa) ✓ DIV gives the integer quotient (7 DIV 2 = 3); MOD gives the remainder (7 MOD 2 = 1). MOD is used to check divisibility (e.g. n MOD 2 = 0 means n is even).
✗ Confusing <> (not equal) with < (less than) or > (greater than) ✓ In pseudo-code, <> means 'not equal to'. < means 'less than' and > means 'greater than'. These are different relational operators.
Write pseudo-code that inputs a number and determines whether it is divisible by both 3 and 5, divisible by 3 only, divisible by 5 only, or neither. Output an appropriate message for each case. [4 marks]
INPUT number IF number MOD 3 = 0 AND number MOD 5 = 0 THEN OUTPUT 'Divisible by both 3 and 5' ELSE IF number MOD 3 = 0 THEN OUTPUT 'Divisible by 3 only' ELSE IF number MOD 5 = 0 THEN OUTPUT 'Divisible by 5 only' ELSE OUTPUT 'Not divisible by 3 or 5' ENDIF
AO1 (Computational Thinking — 40%): Demonstrate knowledge and understanding of the principles and concepts of computer science, including arithmetic and relational operators: DIV and MOD for AQA 8525, OCR J277 & Edexcel 1CP2.
AO2 (Application — 40%): Apply knowledge and understanding of computer science, including arithmetic and relational operators: DIV and MOD to analyse problems in computational terms and to design, write and evaluate solutions.
AO3 (Evaluation — 20%): Evaluate the effectiveness, correctness and efficiency of computational solutions, including arithmetic and relational operators: DIV and MOD, and make reasoned judgements about trade-offs.
Get the best revision books and guides to boost your grades.