Assignment 6 – pseudocode
Assignment 6 – pseudocode
Assignment 6 – pseudo-code
SKIPPED – you will receive full credit
is assignment is an individual activity. It asks you to interpret and write algorithms
using the pseudo-code notation we have studied in class.
1. Read the pseudo-code below and answer the questions that follow.
step 1. let Y be X + 5
step 2. if Y > 0 then set X to Y * 2
step 3. set X to X * 3
step 4. output X
d. Trace the algorithm with the input X = -3. What does it output?
e. Trace the algorithm with the input X = -7. What does it output?
2 of 3 Prof. League – Spring 2014 – Assignment 6 – pseudo-code
2. In this problem, you will write down an algorithm to add two-digit numbers in base
ten. As shown in the figure, your input variables are X₁, X₀, Y₁, and Y₀. Each variable
holds a single-digit integer.
When your algorithm is finished, the answer should be in the variables Z₂, Z₁, and Z₀
– each holding a single digit. For example, if I want to add 56+94, the algorithm will
start with
X1 = 5 X0 = 6
Y1 = 9 Y0 = 4
Z2 = 1 Z1 = 5 Z0 = 0
Your algorithm should work for any single-digits provided in the input variables.
CS101 – Fundamentals of Computer and Information Sciences – LIU 3 of 3
3. Here, C refers to a sequence of variables (an array), and the notation C[I] uses the value
of I to determine which C to access.
Below are the initial values of the array, and other variables you will use.
K :
N :
I :
C[1] : apple
C[2] : apple
C[3] : banana
C[4] : carrot
C[5] : carrot
C[6] : carrot
C[7] : date