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
This note was uploaded on 10/28/2010 for the course CSCI 1001 taught by Professor Staff during the Spring '08 term at Minnesota.
 Spring '08
 Staff

Click to edit the document details