Complete mastery of pre-tested library routines: MOD, DIV, ROUND, RANDOM, and string manipulation for Cambridge IGCSE (0478/0984) and O Level (2210).
MOD(10, 3) → 1.DIV(10, 3) → 3.ROUND(6.97354, 2) → 6.97.Value ← RANDOM().LENGTH("Computer Science") → 16.SUBSTRING("Computer Science", 10, 7) → "Science".UCASE("hello") → "HELLO", LCASE("HELLO") → "hello".Many programming language development systems include library routines that are ready to incorporate into a program. These routines are fully tested and ready for use.
A programming language IDE usually includes a standard library of functions and procedures. These standard library routines perform many types of everyday tasks — such as mathematical operations, number conversions, and the string handling discussed in Section 8.1.4.
Each programming language has many library routines for standard tasks commonly required by programs. Sometimes a set of routines needs to be specifically identified or imported at the top of a program. For example, in Java, the statement import java.lang.String; is required at the start of a program to provide access to the string handling library. In Python, statements like import math and import random load external libraries.
In Cambridge IGCSE Pseudocode, library routines are built directly into the syllabus — you can call them immediately in expressions or assignment statements without import declarations!
You will need to use four core mathematical library routines in your programs for IGCSE Computer Science:
| Library Routine | Operation | Example in Pseudocode | Result |
|---|---|---|---|
MOD |
Returns remainder of a division | Value1 ← MOD(10, 3) |
1 |
DIV |
Returns quotient (whole number part) | Value2 ← DIV(10, 3) |
3 |
ROUND |
Rounds to a given decimal places | Value3 ← ROUND(6.97354, 2) |
6.97 |
RANDOM |
Returns a random number between 0 and 1 inclusive | Value4 ← RANDOM() |
0.81... |
Standard division (10 / 3) gives a floating-point number (3.3333...). In computer science algorithms, we often need to separate integer division into its quotient and remainder:
MOD(10, 3) returns 1.
Key Exam Uses:
• Check if number is even: IF MOD(Num, 2) = 0 THEN
• Check if number is a multiple of 5: IF MOD(Num, 5) = 0 THEN
• Extracting cents / pennies: Cents ← MOD(TotalCents, 100)
DIV(10, 3) returns 3.
Key Exam Uses:
• Minutes to whole hours: Hours ← DIV(TotalMins, 60)
• Dollars from total cents: Dollars ← DIV(TotalCents, 100)
• Binary conversion: repeatedly dividing by 2
DECLARE TotalSeconds : INTEGER
DECLARE Minutes : INTEGER
DECLARE SecondsRemaining : INTEGER
TotalSeconds ← 185
// DIV gives the whole minutes (3)
Minutes ← DIV(TotalSeconds, 60)
// MOD gives the remaining seconds (5)
SecondsRemaining ← MOD(TotalSeconds, 60)
OUTPUT Minutes, " minutes and ", SecondsRemaining, " seconds"
Numerical processing in algorithms requires controlled precision and stochastic (random) selection:
Rounds a REAL value to a given number of decimal places.
• ROUND(6.97354, 2) → 6.97
• ROUND(3.14159, 0) → 3
• ROUND(8.756, 1) → 8.8
Returns a pseudo-random REAL value between 0 and 1 inclusive (e.g. 0.48291...).
RANDOM() with INT():
DieRoll ← INT(RANDOM() * 6) + 1
In Cambridge Paper 2, string operations are formally classified as standard library routines. Always adhere to the official textbook specifications:
| Length | Language | Notes |
|---|---|---|
LENGTH("Computer Science")LENGTH(MyString) |
Pseudocode |
Text in quotes can be used or a variable with data type string. Returns integer count: 16.
|
| Substring | Language | Notes |
|---|---|---|
SUBSTRING("Computer Science", 10, 7)SUBSTRING(MyString, 10, 7) |
Pseudocode |
Text in quotes can be used or a variable with data type string. • First parameter: is the string. • Second parameter: is the position of the start character. • Third parameter: is the length of the required substring. Pseudocode strings start at position one. |
| Upper | Language | Notes |
|---|---|---|
UCASE("Computer Science")UCASE(MyString) |
Pseudocode |
Text in quotes can be used or a variable with data type string. Returns: "COMPUTER SCIENCE".
|
| Lower | Language | Notes |
|---|---|---|
LCASE("Computer Science")LCASE(MyString) |
Pseudocode |
Text in quotes can be used or a variable with data type string. Returns: "computer science".
|
DECLARE TextStr : STRING
DECLARE UpperStr : STRING
DECLARE LowerStr : STRING
TextStr ← "Computer Science"
UpperStr ← UCASE(TextStr) // "COMPUTER SCIENCE"
LowerStr ← LCASE(TextStr) // "computer science"
OUTPUT "Uppercase: ", UpperStr
OUTPUT "Lowercase: ", LowerStr
OUTPUT "Extracted: ", SUBSTRING(TextStr, 10, 7)
OUTPUT "Length: ", LENGTH(TextStr)
| Operation | Cambridge Pseudocode | 🐍 Python | ☕ Java |
|---|---|---|---|
| Remainder | MOD(10, 3) | 10 % 3 | 10 % 3 |
| Integer Division | DIV(10, 3) | 10 // 3 | 10 / 3 (integers) |
| Rounding | ROUND(Val, 2) | round(val, 2) | Math.round(val) |
| Random Number | RANDOM() | random.random() | Math.random() |
| Length | LENGTH(S) | len(s) | s.length() |
| Substring | SUBSTRING(S, 10, 7) | s[9:16] (0-indexed) | s.substring(9, 16) |
| Uppercase | UCASE(S) | s.upper() | s.toUpperCase() |
| Lowercase | LCASE(S) | s.lower() | s.toLowerCase() |
Task: An online shopping system asks the user for a product code and a quantity of items ordered.
Each box holds 12 items. Write pseudocode that:
1. Inputs the item code and standardizes it in all uppercase letters using UCASE.
2. Calculates how many full boxes are needed using DIV.
3. Calculates how many loose items remain using MOD.
4. Outputs the standardized code, full boxes, and remaining items.
Hover or tap the box to reveal the examiner-approved model answer. Click Run Code to launch it live in the IDE!
DECLARE ProductCode : STRING DECLARE Quantity : INTEGER DECLARE FullBoxes : INTEGER DECLARE LooseItems : INTEGER OUTPUT "Enter product code:" INPUT ProductCode OUTPUT "Enter quantity of items:" INPUT Quantity // Standardize code to uppercase ProductCode ← UCASE(ProductCode) // Calculate boxes (quotient) and leftover items (remainder) FullBoxes ← DIV(Quantity, 12) LooseItems ← MOD(Quantity, 12) OUTPUT "Product: ", ProductCode OUTPUT "Full Boxes: ", FullBoxes OUTPUT "Loose Items: ", LooseItems
Remember: DIV is the whole division result (Quotient). MOD is what's left over (Remainder). E.g., DIV(7, 2) = 3, while MOD(7, 2) = 1.
Pseudocode strings are 1-indexed! SUBSTRING("Computer Science", 1, 3) returns "Com". If you write SUBSTRING(S, 0, 3) you lose marks.
In Cambridge pseudocode, the 3rd parameter of SUBSTRING(String, Start, Length) is the number of characters to take, NOT the finishing character index!
PseudoStudio's online compiler includes live syntax highlighting, autocomplete, and deterministic execution for all Cambridge library routines: MOD, DIV, ROUND, RANDOM, LENGTH, SUBSTRING, UCASE, and LCASE.
Open our free online pseudocode editor with built-in library routine autocomplete and live execution.