|
-
May 13th, 2007, 07:43 AM
#1
Help with an algorithm.
Here is a simple algorithm that uses a while loop.
set theinitial valueofcount to10
while(NOT(count is 0))
write the valueofcount in theoutput window
decreasecount by 1
move to thenext lineof theoutput window
write 'zero' in theoutput window
Figure 4 An algorithm using a while loop
(a)What will be written to the output window when this algorithm
is run? [2]
(b)Suppose the second line of the algorithm were changed to read
while(count is 11)
What will be written when the modified algorithm is run? [2]
Suppose you are a given a pile of cards, each of which shows one
of the following four shapes: square or circle, shaded or unshaded
(Figure5). You can assume these are the only possibilities.
Write a set of instructions using while loop and if...else
selection structures to sort the pile of cards according to the
symbols they display and write an appropriate message for each
card, for example 'shaded circle' or 'unshaded square'. Each
message should be on a new line.
In your answer you should use indentation to help make the
structure of the algorithm clear.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|