Pseudocode Practice Questions with Answers
Solve 50+ Cambridge Computer Science pseudocode questions with step-by-step model answers. Master loops, arrays, conditionals, subroutines, and trace tables. Write your solutions and test them instantly using our free online compiler.
Variables, Arithmetic & Expressions
Practice declaring data types, arrow assignment (←), constant values, and arithmetic operations.
Question 1: Store Discount & Final Price Calculator
Write a pseudocode algorithm that prompts the user to enter an item price (REAL) and a discount percentage (INTEGER). Calculate the discount amount and the final discounted price, then output both values clearly formatted.
👁️ Show Model Answer & Solution Code
DECLARE ItemPrice : REAL DECLARE DiscountPct : INTEGER DECLARE DiscountAmt : REAL DECLARE FinalPrice : REAL INPUT ItemPrice INPUT DiscountPct DiscountAmt ← ItemPrice * (DiscountPct / 100) FinalPrice ← ItemPrice - DiscountAmt OUTPUT "Discount: ", DiscountAmt OUTPUT "Final Price: ", FinalPrice
Question 2: Circle Area & Circumference Calculator
Write a pseudocode algorithm that inputs the Radius (REAL) of a circle. Declare a CONSTANT PI ← 3.14159. Compute Circumference = 2 * PI * Radius and Area = PI * Radius * Radius. Output both calculated results.
👁️ Show Model Answer & Solution Code
CONSTANT PI ← 3.14159 DECLARE Radius : REAL DECLARE Circumference : REAL DECLARE Area : REAL INPUT Radius Circumference ← 2 * PI * Radius Area ← PI * Radius * Radius OUTPUT "Circumference: ", Circumference OUTPUT "Area: ", Area
Question 3: Swap Two Variable Values
Write an algorithm that prompts for two integers X and Y, swaps their stored values using a temporary variable Temp, and outputs the swapped values of X and Y.
👁️ Show Model Answer & Solution Code
DECLARE X : INTEGER DECLARE Y : INTEGER DECLARE Temp : INTEGER INPUT X INPUT Y Temp ← X X ← Y Y ← Temp OUTPUT "X: ", X OUTPUT "Y: ", Y
Conditionals & Selection (IF / ELSE / CASE)
Practice decision-making logic using nested IF...THEN...ELSE...ENDIF and logical operators (AND, OR, NOT).
Question 4: Student Exam Grade Classification
Write a pseudocode algorithm that inputs a student's score (0 to 100). Output "Distinction" if score ≥ 80, "Merit" if score ≥ 60, "Pass" if score ≥ 40, and "Fail" otherwise.
👁️ Show Model Answer & Solution Code
DECLARE Score : INTEGER
INPUT Score
IF Score >= 80 THEN
OUTPUT "Distinction"
ELSE
IF Score >= 60 THEN
OUTPUT "Merit"
ELSE
IF Score >= 40 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
ENDIF
ENDIF
Question 5: Movie Ticket Pricing Structure
Write an algorithm that prompts for a customer's Age (INTEGER). If Age < 12 output "Child: $5", if Age < 65 output "Adult: $12", otherwise output "Senior: $8".
👁️ Show Model Answer & Solution Code
DECLARE Age : INTEGER
INPUT Age
IF Age < 12 THEN
OUTPUT "Child: $5"
ELSE
IF Age < 65 THEN
OUTPUT "Adult: $12"
ELSE
OUTPUT "Senior: $8"
ENDIF
ENDIF
Question 6: Month Days & Leap Year Logic
Write a pseudocode algorithm that inputs a Month number (1 to 12). If Month is 2, output "28 or 29 days". If Month is 4, 6, 9, or 11 output "30 days". Otherwise output "31 days".
👁️ Show Model Answer & Solution Code
DECLARE Month : INTEGER
INPUT Month
IF Month = 2 THEN
OUTPUT "28 or 29 days"
ELSE
IF Month = 4 OR Month = 6 OR Month = 9 OR Month = 11 THEN
OUTPUT "30 days"
ELSE
OUTPUT "31 days"
ENDIF
ENDIF
Iteration & Loops (FOR / WHILE / REPEAT)
Master definite iteration (FOR...TO...NEXT) and indefinite iteration (WHILE...DO...ENDWHILE, REPEAT...UNTIL).
Question 7: Calculate Total Sum and Average of N Inputs
Write a pseudocode algorithm that inputs 5 integer values using a FOR loop, accumulates their total sum, computes their rounded average, and outputs both results.
👁️ Show Model Answer & Solution Code
DECLARE Val : INTEGER
DECLARE Total : INTEGER
DECLARE Average : INTEGER
DECLARE i : INTEGER
Total ← 0
FOR i ← 1 TO 5
INPUT Val
Total ← Total + Val
NEXT i
Average ← ROUND(Total / 5)
OUTPUT "Total: ", Total
OUTPUT "Average: ", Average
Question 8: Multiples of 3 Generator
Write an algorithm using a WHILE loop to print all positive multiples of 3 strictly less than 20 (i.e. 3, 6, 9, 12, 15, 18).
👁️ Show Model Answer & Solution Code
DECLARE Num : INTEGER
Num ← 3
WHILE Num < 20 DO
OUTPUT Num
Num ← Num + 3
ENDWHILE
Question 9: Factorial Calculator Using REPEAT Loop
Write a pseudocode algorithm that inputs a positive integer N (e.g. 5) and computes its factorial (N!) using a REPEAT...UNTIL loop.
👁️ Show Model Answer & Solution Code
DECLARE N : INTEGER
DECLARE Fact : INTEGER
DECLARE Count : INTEGER
INPUT N
Fact ← 1
Count ← 1
REPEAT
Fact ← Fact * Count
Count ← Count + 1
UNTIL Count > N
OUTPUT "Factorial: ", Fact
Data Structures & 1D/2D Arrays
Practice 1-indexed array declarations (ARRAY[1:N] OF INTEGER), linear search, and finding maximum/minimum values.
Question 10: Find Highest Mark in a Class Array
An array Marks[1:5] contains 5 student marks: [65, 82, 45, 92, 78]. Write a pseudocode algorithm to loop through the array and find and output the highest mark.
👁️ Show Model Answer & Solution Code
DECLARE Marks : ARRAY[1:5] OF INTEGER
DECLARE Max : INTEGER
DECLARE i : INTEGER
Marks[1] ← 65
Marks[2] ← 82
Marks[3] ← 45
Marks[4] ← 92
Marks[5] ← 78
Max ← Marks[1]
FOR i ← 2 TO 5
IF Marks[i] > Max THEN
Max ← Marks[i]
ENDIF
NEXT i
OUTPUT "Highest Mark: ", Max
Question 11: Array Linear Search Algorithm
Given an array Scores[1:4] = [12, 45, 67, 89], write an algorithm that inputs a SearchVal. Output "Found at index X" if present, or "Not Found" if the value is not in the array.
👁️ Show Model Answer & Solution Code
DECLARE Scores : ARRAY[1:4] OF INTEGER
DECLARE SearchVal : INTEGER
DECLARE Found : BOOLEAN
DECLARE i : INTEGER
Scores[1] ← 12
Scores[2] ← 45
Scores[3] ← 67
Scores[4] ← 89
INPUT SearchVal
Found ← FALSE
FOR i ← 1 TO 4
IF Scores[i] = SearchVal THEN
OUTPUT "Found at index: ", i
Found ← TRUE
ENDIF
NEXT i
IF Found = FALSE THEN
OUTPUT "Not Found"
ENDIF
Question 12: Array Sum, Average, and Threshold Counter
Write a pseudocode algorithm that declares an array Scores of 10 integers. Prompt the user to input 10 scores, calculate the total sum and average score, and output the count of scores greater than 50.
👁️ Show Model Answer & Solution Code
DECLARE Scores : ARRAY[1:10] OF INTEGER
DECLARE Total, Count, I : INTEGER
DECLARE Average : REAL
Total ← 0
Count ← 0
FOR I ← 1 TO 10
OUTPUT "Enter score ", I, ":"
INPUT Scores[I]
Total ← Total + Scores[I]
IF Scores[I] > 50 THEN
Count ← Count + 1
ENDIF
NEXT I
Average ← Total / 10
OUTPUT "Total:", Total
OUTPUT "Average:", Average
OUTPUT "Scores > 50:", Count
Functions, Subroutines & Parameters
Practice defining FUNCTION...RETURNS, calling subroutines with parameters, and handling return values.
Question 13: Rectangle Area Function
Write a pseudocode FUNCTION CalcArea(W : REAL, H : REAL) RETURNS REAL that returns the calculated rectangle area (W * H). Call the function with Width = 5.0 and Height = 4.0 and output the area.
👁️ Show Model Answer & Solution Code
FUNCTION CalcArea(W : REAL, H : REAL) RETURNS REAL
RETURN W * H
ENDFUNCTION
DECLARE Area : REAL
Area ← CalcArea(5.0, 4.0)
OUTPUT "Area: ", Area
Question 14: IsEven Check Function
Write a FUNCTION IsEven(N : INTEGER) RETURNS BOOLEAN that returns TRUE if N MOD 2 = 0, otherwise FALSE. Call the function with 14 and output "Even" or "Odd".
👁️ Show Model Answer & Solution Code
FUNCTION IsEven(N : INTEGER) RETURNS BOOLEAN
IF N MOD 2 = 0 THEN
RETURN TRUE
ELSE
RETURN FALSE
ENDIF
ENDFUNCTION
IF IsEven(14) THEN
OUTPUT "Even"
ELSE
OUTPUT "Odd"
ENDIF
Trace Tables & Output Prediction
Practice dry-running algorithms on paper or interactive matrices to track changing variable states line by line.
Question 15: Dry Run Trace Table for Even Sum Loop
Complete the trace table for the given algorithm when the input values are 14, 27, 8, 32, -1.
👁️ Show Expected Trace Matrix
| Count | Sum | Value | OUTPUT |
|---|---|---|---|
| 0 | 0 | 14 | |
| 1 | 14 | 27 | |
| 8 | |||
| 2 | 22 | 32 | |
| 3 | 54 | -1 | |
| 3 | 54 | -1 | Even Sum: 54 |
Build Your Custom AI Practice Exam
Select your syllabus, difficulty, and target topics to generate an instant, automated practice session with real-time feedback.
Practice Session Ready
IGCSE 0478/0984
25 Marks
ESTIMATED SCORE
18 Mins
TARGET DURATION
🔒 Free 1-click Google Sign-in to unlock and save progress
How to Excel in Cambridge Computer Science Pseudocode Exams
1. Keyword Capitalization
Cambridge mark schemes strictly require keywords in UPPERCASE: DECLARE, INPUT, OUTPUT, IF...THEN...ELSE...ENDIF, FOR...TO...NEXT.
2. Arrow Assignment (←)
Variable assignment uses ← (or <-), never =. The = symbol is reserved strictly for equality tests in IF conditions.
3. 1-Indexed Arrays
Unlike Python or Java, Cambridge pseudocode arrays are indexed starting from 1 by default: DECLARE StudentNames : ARRAY[1:30] OF STRING.
Frequently Asked Questions
←), explicit variable declarations with types, and 1-indexed arrays.