You are on page 1of 2

ALGORITHM A DAY May 2nd

Question Answer

A programmer has been asked to write a subroutine which will


accept a string, find the length of the string and output the number of
characters it contains.

Write a subroutine, in pseudocode, which will receive a string and


output the number of characters the string contains.

CSUK CSUK:Teacher CSUK:ReviseCS


computerscienceuk.com | csuk.io teacher.computerscienceuk.com | csukteacher.com revisecs.computerscienceuk.com | revisecs.com
ALGORITHM A DAY May 2nd

Question Answer

A programmer has been asked to write a subroutine which will ***There are always different ways to solve a problem. This algorithm is
accept a string, find the length of the string and output the number of just an example. What is important is that the logic is correct!***
characters it contains.
LOGIC:
Write a subroutine, in pseudocode, which will receive a string and
output the number of characters the string contains. •Declare a procedure with a parameter
•Find the length of the parameter value and store the answer
•Output the answer
•Call the procedure passing a parameter of string “computer”

EXAMPLE ALGORITHM:

procedure lengthOfString(x)
answer = x.length
print(answer)
endprocedure

lengthOfString(“Computer”)

CSUK CSUK:Teacher CSUK:ReviseCS


computerscienceuk.com | csuk.io teacher.computerscienceuk.com | csukteacher.com revisecs.computerscienceuk.com | revisecs.com

You might also like