{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Set 5.5 Questions

# Set 5.5 Questions - Exercise Set 5.5 Exercises 1-5 contain...

This preview shows pages 1–2. Sign up to view the full content.

Exercise Set 5.5 Exercises 1-5 contain a while loop and a predicate. In each case show that if the predicate is true before entry to the loop, then it is also true after exit from the loop. 1. loop: while (m 2: 0 and m ~ 100) m:= m + I n := n - I end while predicate: m + n = 100 2. loop: while (m 2: 0 and m ~ 100) m :=m+4 n:= n - 2 end while predicate: m + n is odd 3. loop: while (m 2: 0 and m ~ 100) m :=3·m n:= 5·n end while predicate: m 3 > n 2 4. loop: while (n 2: 0 and n ~ '100) n := n + I end while predicate: 2" < (n + 2)! 5. loop: while (n 2: 3 and n ~ 100) n :=n+ 1 end while predicate: 2n + I ~ 2" Exercises 6-9 each contain a while loop annotated with a pre- and a post-condition and also a loop invariant. In each case, use the loop invariant theorem to prove the correctness of the loop with respect to the pre- and post-conditions. 6. [Pre-coruiition: m is a nonnegative integer, x is a real number, i = 0, andexp = J.] while (i =1= m) I. exp := exp·x 2.i :=i+ I end while [Post-condition: exp = x m ] loop invariant: J (n) is "exp = x" and i = n." 7. [Pre-coruiition: largest = A[I] arui i = II while (i =1= m) I. i := i + I 2. irA [i] > largest then

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 2

Set 5.5 Questions - Exercise Set 5.5 Exercises 1-5 contain...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online