0% found this document useful (0 votes)
29 views2 pages

05-04 SUBROUTINES - Algorithm 4

The document describes a question and answer about writing a function in pseudocode. A programmer needs to write a function that takes a user's age as a parameter, calculates their age 50 years from now by adding 50 to the parameter, and returns the result. The answer provides an example pseudocode algorithm that declares a function that takes a parameter x, adds 50 to x and stores it in a variable called answer, returns answer, calls the function passing 15 as a parameter and stores the return value in a variable called result, and prints result.

Uploaded by

Zuhdija
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views2 pages

05-04 SUBROUTINES - Algorithm 4

The document describes a question and answer about writing a function in pseudocode. A programmer needs to write a function that takes a user's age as a parameter, calculates their age 50 years from now by adding 50 to the parameter, and returns the result. The answer provides an example pseudocode algorithm that declares a function that takes a parameter x, adds 50 to x and stores it in a variable called answer, returns answer, calls the function passing 15 as a parameter and stores the return value in a variable called result, and prints result.

Uploaded by

Zuhdija
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

ALGORITHM A DAY May 4th

Question Answer

A programmer has been asked to write a function which will receive


the age of a user (e.g. 15) and calculate their age in 50 years,
returning the result back to the main program for outputting.

Write a subroutine, in pseudocode, which shows the logic of the


problem above.

CSUK CSUK:Teacher CSUK:ReviseCS


computerscienceuk.com | csuk.io teacher.computerscienceuk.com | csukteacher.com revisecs.computerscienceuk.com | revisecs.com
ALGORITHM A DAY May 4th

Question Answer

A programmer has been asked to write a function which will receive ***There are always different ways to solve a problem. This algorithm is
the age of a user (e.g. 15) and calculate their age in 50 years, just an example. What is important is that the logic is correct!***
returning the result back to the main program for outputting.
LOGIC:
Write a subroutine, in pseudocode, which shows the logic of the
problem above. •Declare a function with a parameter
•Add 50 to the parameter value and store the result
•Return the result back to the main program
•Call the function passing 15 as an argument, ensuring the function is
assigned to a variable which will receive the returned value.
•Output the returned value.

EXAMPLE ALGORITHM:

function ageInFifty(x)
answer = x + 50
return answer
endfunction

result = ageInFifty(15)
print(result)

CSUK CSUK:Teacher CSUK:ReviseCS


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

You might also like