Writing Algorithms
Practice Exercises
SUBROUTINES / PARAMETERS
GCSE Computer Science (9-1)
www.revisecomputerscience.com
Writing Algorithms - Practice
Algorithm Question
A programmer has been asked to write a subroutine which when called will accept a number, double it and output the result.
Write a subroutine, in pseudocode, which will receive the number 3 and output its value, doubled.
***There are always different ways to solve a problem. This algorithm is just an example. What is important is that the logic is correct!***
LOGIC:
-Declare a procedure with a parameter
-Double the parameter value and store the answer
-Output the answer
-Call the procedure passing a parameter of value 3
EXAMPLE ALGORITHM:
PROCEDURE double(x):
answer = x*2
OUTPUT answer
double(3)