Instructions: The first problem asks you to read a function and determine what it does. The secon problem asks you to write a function given a description.
# Comment: A function with 1 parameter
To function(N):
Set global Var to 1
While N > 0 do:
Set Var to Var × N
Set N to N - 1
Return Var
countMs( [1,2,2,3,3,2,1,4,1,2], 2)
it will return 4 because there are four 2s in the list.
Instructions: The next two problems ask you to define a
function in Pseudocode or write a loop algorithm. Model your answers after the Pseudocode
algorithms in the first 2 questions. Be careful about indentation.
# Comment: What is the final value of Var
Set global Var to 0
For each item in list do:
If remainder(item, 4) = 0
Set global Var to Var + item * item