This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: (d) • Tying shoelaces. • Riding a bicycle. (This is similar to the last problem in HW 1; see the HW 1 key iF you missed this.) Problem (5) The algorithm prints ’check’ since at its end sum is 16. Here are the values oF i and sum at the end oF the execution oF line 8: i sum2 1 3 41 52 6 3 7 9 8 8 9 16 Note that in the loop you add the value oF i to sum when a[i] is 1, but you subtract 1 From sum when a[i] is 0. Problem (6) Algorithm: 1 Get a regular, shu±ed, deck oF 52 cards in a Face down pile. 2 Set count ← 3 Set numAces ← 3 While numAces < 4 4 Turn over the top card in the pile oF Face down cards 5 IF the card is an ace then 6 Set numAces ← numAces +1 7 Set count ← count +1 8 Output count , ‘ cards turned over’ 9 Stop 2...
View
Full Document
 Spring '08
 Staff
 Logic, Addition, Phil Barry, Phil Barry Jonathon Lawson

Click to edit the document details