Professional Documents
Culture Documents
SOLUTION:
Step 1: Start.
Step 2: Collect all pens.
Step 3: Check every pen individually whether it writes or not.
Step 4: Remove the pens which don’t write.
Step 5: End
2. Suppose you are told that your favorite movie is on television right now, but you are not
sure which channel it is on. Without the use of a program guide (that is, without using
things like TV Guide or the newspaper program listings), find the channel broadcasting the
movie. Assume, of course, that you could recognize any part of the movie if you saw it.
SOLUTION:
Step 1: Start
Step 2: Turn on TV
Step 3: Select channel 1 from Remote.
Step 4: Keep forwarding channels one by one.
Step 5: When you find movie stop forwarding Channels.
Step 6: Enjoy movie.
Step 7: End
3. Given a bag full of cherries, determine whether you could split them evenly among seven
people (so that each person has the same number of cherries, and none are left over). The
result is a yes or no answer.
SOLUTION:
Step 1: Start.
Step 2: Take the cherries and divide them into seven people equally.
Step 3: (number of cherries%7==0)
Step 4: If there are no cherries left in bag
Step 5: Print “Yes”
Step 6: Else print “No”
Step 7: Exit.
B. 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 *
Step 3. set X to X * 3
Step 4. output X
1. Does this algorithm contain a conditional statement? If so, which one?
ANSWER:
Yes, it is conditional statement in step 2 (if Y > 0 then set X to Y * 2)
ANSWER:
No, this algorithm has no iterations
4. Trace the algorithm with the input X = -3. What does it output?
ANSWER:
X=12
5. Trace the algorithm with the input X = -7. What does it output?
ANSWER:
X=-21
SOLUTION:
FLOWCHART
START
X=0
X=X+1
PRINT X
NO IF YES
X< 20
END
Algorithm 2:
Step 1: Read temperature in Fahrenheit,
Step 2: Calculate temperature with formula C=5/9*(F 32),
Step 3: Print C,
SOLUTION:
FLOWCHART
START
Read
temperature in
Fahrenheit
C=5/9*(F-32)
PRINT C
END