Algorithms do calculations and make decisions using operators. In this post you will learn the arithmetic operators (including MOD and DIV), the relational operators used to compare values, and the logical operators AND, OR, NOT with their truth tables.
Build on what you learned in Forms 1–3
These Lower School ICT posts cover the basics of this topic:
- Flowcharts – Sequence, Selection Intro (Class Discussion) – conditions and comparisons
- Scratch – Selection, Sensing, Repetition, Outputting Results. – using conditions in Scratch
In this post:
- Arithmetic operators, MOD and DIV
- Relational operators
- Logical operators AND, OR, NOT
- Truth tables
- Using operators in pseudocode and code
Arithmetic operators
| Operator | Meaning | Example | Result |
|---|---|---|---|
| + | Add | 7 + 3 | 10 |
| − | Subtract | 7 − 3 | 4 |
| * | Multiply | 7 * 3 | 21 |
| / | Divide | 7 / 2 | 3.5 |
| DIV | Whole-number (integer) division – how many times it goes in | 17 DIV 5 | 3 |
| MOD | Remainder after whole-number division | 17 MOD 5 | 2 |
MOD and DIV are very useful. Example: a fete has 135 minutes of music. 135 DIV 60 = 2 hours and 135 MOD 60 = 15 minutes. Another common use: a number is even if number MOD 2 = 0.
Pseudocode
READ total_minutes
hours ← total_minutes DIV 60
minutes ← total_minutes MOD 60
PRINT total_minutes, " minutes = ", hours, " hours and ", minutes, " minutes"
Python
# Convert minutes into hours and minutes using DIV and MOD
total_minutes = int(input("Enter the number of minutes: "))
hours = total_minutes // 60 # DIV
minutes = total_minutes % 60 # MOD
print(total_minutes, "minutes =", hours, "hours and", minutes, "minutes")
C
/* Convert minutes into hours and minutes using DIV and MOD */
#include <stdio.h>
int main(void)
{
int total_minutes, hours, minutes;
printf("Enter the number of minutes: ");
scanf("%d", &total_minutes);
hours = total_minutes / 60; /* DIV (integer division) */
minutes = total_minutes % 60; /* MOD (remainder) */
printf("%d minutes = %d hours and %d minutes\n", total_minutes, hours, minutes);
return 0;
}
Sample run with 135: 135 minutes = 2 hours and 15 minutes. In Python, DIV is // and MOD is %; in C, / between two integers does DIV and % is MOD.
Relational operators
Relational operators compare two values. The answer is always TRUE or FALSE.
| CSEC pseudocode | Meaning | Python | C |
|---|---|---|---|
| < | less than | < | < |
| > | greater than | > | > |
| = | equal to | == | == |
| <= | less than or equal to | <= | <= |
| >= | greater than or equal to | >= | >= |
| <> | not equal to | != | != |
Example: IF age >= 17 THEN PRINT "You may apply for a learner’s permit". You can practise these in Relational Operators – A practical Exercise.
Logical operators and truth tables
- AND – TRUE only if both conditions are TRUE.
- OR – TRUE if at least one condition is TRUE.
- NOT – reverses the value: NOT TRUE = FALSE.
A truth table shows the result for every possible combination of inputs.
| A | B | A AND B | A OR B |
|---|---|---|---|
| TRUE | TRUE | TRUE | TRUE |
| TRUE | FALSE | FALSE | TRUE |
| FALSE | TRUE | FALSE | TRUE |
| FALSE | FALSE | FALSE | FALSE |
| A | NOT A |
|---|---|
| TRUE | FALSE |
| FALSE | TRUE |
Everyday example: A child gets into the Carnival kiddies’ fete free IF they are under 12 AND with an adult. A 10-year-old alone → TRUE AND FALSE = FALSE, so no free entry. A scholarship is given IF average >= 80 OR the student won the science fair – only one needs to be TRUE.
Pseudocode
READ age, with_adult
IF age < 12 AND with_adult = TRUE THEN
PRINT "Free entry"
ELSE
PRINT "Pay at the gate"
ENDIF
In Python these are written and, or, not; in C they are &&, || and !.
Video: Boolean Logic & Logic Gates: Crash Course Computer Science #3 – https://www.youtube.com/watch?v=gI-qXk7XojA
Try it: Complete the truth table
Type TRUE or FALSE in each box, then check.
| A | B | A AND B | A OR B | NOT A |
|---|---|---|---|---|
| TRUE | TRUE | |||
| TRUE | FALSE | |||
| FALSE | TRUE | |||
| FALSE | FALSE |
Try it: MOD and DIV practice
Work out each answer.
| Expression | Answer |
|---|---|
| 17 DIV 5 | |
| 17 MOD 5 | |
| 20 MOD 4 | |
| 9 DIV 2 | |
| 250 MOD 60 |
Related
Related: Relational Operators – A practical Exercise
Paper 1 practice (multiple choice)
Choose the best answer for each question. Try them all before you check.
1. What is the value of 23 MOD 4?
(A) 5
(B) 3
(C) 5.75
(D) 4
2. What is the value of 23 DIV 4?
(A) 5
(B) 3
(C) 5.75
(D) 6
3. Which relational operator means “not equal to” in CSEC pseudocode?
(A) =
(B) <>
(C) >=
(D) !
4. If A is TRUE and B is FALSE, what is A AND B?
(A) TRUE
(B) FALSE
(C) Both
(D) Cannot tell
5. If A is FALSE and B is TRUE, what is A OR B?
(A) TRUE
(B) FALSE
(C) NOT B
(D) Cannot tell
Show answers
1. B
2. A
3. B
4. B
5. A
Paper 2 practice (structured question)
A minibus company charges students half price IF they are in uniform AND travelling before 6:00 p.m. A program uses the Boolean variables in_uniform and before_six.
(a) State the result of EACH of the following:
(i) 29 MOD 7 (1 mark)
(ii) 29 DIV 7 (1 mark)
(b) Copy and complete a truth table for in_uniform AND before_six, showing all FOUR combinations. (4 marks)
(c) Explain the difference between the AND and OR logical operators. (2 marks)
(d) Write a pseudocode IF statement that prints “Half price” when a student qualifies, and “Full price” otherwise. (2 marks)
Total: 10 marks
Show answers
(a)
(i) 1 (1 mark)
(ii) 4 (1 mark)
(b)
• TRUE, TRUE → TRUE (1 mark)
• TRUE, FALSE → FALSE (1 mark)
• FALSE, TRUE → FALSE (1 mark)
• FALSE, FALSE → FALSE (1 mark)
(c) AND gives TRUE only when both conditions are TRUE (1 mark); OR gives TRUE when at least one of the conditions is TRUE (1 mark).
(d) IF in_uniform = TRUE AND before_six = TRUE THEN PRINT “Half price” (1 mark); ELSE PRINT “Full price” ENDIF (1 mark).
Next: Testing Algorithms with Trace Tables (Desk Checks and Dry Runs)
Syllabus link: This post is relevant to the CSEC® Information Technology Syllabus (CXC 30/G/SYLL 17), Section 7: Problem-Solving and Program Design, Specific Objective 6 (“represent algorithms in the form of flowchart and pseudocode”).
Attributions to media used in this post:
No third-party images are used in this post. Embedded videos are credited on YouTube to their channels.
Updates
2026/10/16
– Syntax highlighting added to code examples.
© 2026 Vedesh Kungebeharry. All rights reserved.