Instructions: The first three problems ask you to read a Pseudocode algorithm. Trace through each of them by hand, keeping track of the variables, to determine the answer to the question.
Problem Solution # Comment: A function definition that takes 1 parameter To functionA(a): Return: a * a - a Trace: functionA(5) returns 5 * 5 - 5 = 20
Problem Solution # Comment: A mystery function To mystery(X, Y): If X = Y then do: Return X * Y If X > Y then do: Return X - Y else do: Return Y - X X Y Return ------------------------ 3 3 9 mystery(3,3) returns 9 2 5 3 mystery(2,5) returns 3
Instructions: The next three problems ask you to define a
function in Pseudocode. Model your answers after the Pseudocode
algorithms in the first 3 questions.
# A function that computes the area of a circle with radius R To areaOfCircle(R): Return 3.14 * R * R
# A function to compute mile per gallon, given mi for miles and g for gallons To mpg( mi, g): Return mi / g