Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
15 views

Assignment 6 – pseudocode

The document outlines Assignment 6 for a CS101 course, focusing on interpreting and writing algorithms in pseudo-code. It includes tasks such as analyzing a given pseudo-code algorithm, writing an algorithm to add two-digit numbers, and determining the output of an algorithm that processes an array. Students are expected to demonstrate their understanding of conditional statements, iteration, and algorithm tracing.

Uploaded by

vaghelisz
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)
15 views

Assignment 6 – pseudocode

The document outlines Assignment 6 for a CS101 course, focusing on interpreting and writing algorithms in pseudo-code. It includes tasks such as analyzing a given pseudo-code algorithm, writing an algorithm to add two-digit numbers, and determining the output of an algorithm that processes an array. Students are expected to demonstrate their understanding of conditional statements, iteration, and algorithm tracing.

Uploaded by

vaghelisz
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/ 3

CS101 – Fundamentals of Computer and Information Sciences – LIU 1 of 3

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

a. Does this algorithm contain a conditional statement? If so, which one?

b. Does this algorithm contain iteration? If so, which steps repeat?

c. Trace the algorithm with the input X = 4. What does it output?

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

and in the end, the Z variables will have the result:

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.

step 1. set K to C[1]


step 2. set N to 1
step 3. set I to 2
step 4. if I > 7 then output N then K and stop
step 5. if C[I] = K then set N to N+1 and go to step 9
step 6. output N then K
step 7. set K to C[I]
step 8. set N to 1
step 9. set I to I+1
step 10. go back to step 4.

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

What is the output of the algorithm?

You might also like