IGCSE_Pseudocode_Answers_Detailed
IGCSE_Pseudocode_Answers_Detailed
PART 1: ARRAYS
Q1.1
- Iteration statement: These lines control the loop for processing the list:
Line 2: Initializes and begins the loop that iterates through the list.
Line 9: Marks the end of the iteration process.
This algorithm searches for a specific number within an array of 50 integers. It uses a loop
to traverse the array and compares each element with the target number. If the number is
found, its position is output, and the loop terminates early.
Detailed Pseudocode:
DECLARE Values : ARRAY[1:50] OF INTEGER
DECLARE MyNumber : INTEGER
DECLARE Found : BOOLEAN
DECLARE Position : INTEGER
Bubble sort is a simple sorting algorithm that repeatedly steps through the list, compares
adjacent elements, and swaps them if they are in the wrong order. This process continues
until the list is sorted.
Detailed Pseudocode:
DECLARE Values : ARRAY[1:50] OF INTEGER
DECLARE Temp : INTEGER
FOR I ← 1 TO 49
FOR J ← 1 TO (50 - I)
IF Values[J] > Values[J + 1] THEN
Temp ← Values[J]
Values[J] ← Values[J + 1]
Values[J + 1] ← Temp
ENDIF
NEXT J
NEXT I
Q1.3
The purpose of this algorithm is to take a list of names as input, sort them in ascending
alphabetical order using a bubble sort algorithm, and then output the sorted list. This
ensures that the names are organized for further use or display.
1. Add comments to explain each section of the code and its purpose.
2. Use meaningful and descriptive variable names to make the logic clear.
3. Break down the sorting logic into a separate function or procedure for modularity.
4. Include error handling for invalid or empty inputs.
Q2.1
A **parameter** is a variable used to pass information between procedures or functions
and the main program.
Q2.2
Q2.3
- **DIV:** Performs integer division, returning only the quotient. For example, 17 DIV 5
results in 3.
- **ROUND:** Rounds a real number to the nearest specified number of decimal places. For
example, ROUND(3.14159, 2) results in 3.14.
Q2.4
- **MOD:** Returns the remainder of integer division. For example, 17 MOD 5 results in 2.
- **RANDOM:** Generates a random number within a specified range. For example,
RANDOM(1, 10) generates a number between 1 and 10 inclusive.
Q2.5
Q3.1
- **String Manipulation:**
DECLARE FullText : STRING = "Computer Science"
DECLARE Substring : STRING
- **File Handling:**
DECLARE FileHandle : FILE
OPEN FileHandle FOR WRITE AS "Subjects.txt"
WRITE FileHandle, Substring
CLOSE FileHandle
Q3.2
- **String Operations:**
DECLARE Quote : STRING = "Learning Never Exhausts The Mind"
DECLARE Extracted : STRING