Set 5.5 Questions

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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/12/2011 for the course MATH 103 taught by Professor Wouters during the Spring '08 term at Wisc Oshkosh.

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 Right Arrow Icon
Ask a homework question - tutors are online