# 001_Baddam_Krishna_Assignment_2 - CS536 Homework #3...

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

CS536 Homework #3 CWID:A20193023 1A. {a≥0 and b≥0} x:=a; y:=b; { gcd(x,y)=gcd(a,b)} while x≠y loop { x ≠ y ^ 0<x<=a ^ 0<y<=b } if x>y the x:=x-y else y:=y-x; {((x ≤ y) v (y ≤ x)) ^ 0<=x<=a ^ 0<=y<=b } end; g:=x; { gcd(x,y)=gcd(a,b)=g } {g=gcd (a,b)} The program is partially correct because if a or b is 0,the program never terminates .Hence the program would be correct by adding the above assertions. 2A. a. { x + y = z } x := y { 2y = z } x+y=z => (2y= z) y x x+y=z => 2y= z Incorrect b. { x = 2 } x := 2 * x + 1 { odd(x) } x=2 =>(odd(x)) x 2x+1 x=2 =>odd(2x+1) odd(2*2+1) odd(5) Correct c. { true } x := 3 { x = 3 } True =>(x =3) 3 x True =>(3 =3) Correct d. { true } x := 3 { odd(x) } True => (odd(x)) 3 x True =>odd(3) Correct

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

View Full Document
e. { false } x := 0 { x = 1 } False =>(x =1) 0 x False => x= 0 Correct f. {even(x+y)} x := 5x-3y {even(x+y)} even(x+y)=> (even(x+y)) x 5x-3y even(x+y)=>(even(5x-3y+y) even(x+y)=>even(5x-2y) Incorrect g. {true} x:=y {x≤ y} True =>(x≤ y) y x True =>(y<y or y=y)
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 05/04/2011 for the course CS 536 taught by Professor Cs536 during the Spring '08 term at Illinois Tech.

### Page1 / 5

001_Baddam_Krishna_Assignment_2 - CS536 Homework #3...

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

View Full Document
Ask a homework question - tutors are online