Question

17. hy the correctness of the following program segment with the precondition and postcondition shown {x60 if x > 0 then y =

0 0
Add a comment Improve this question Transcribed image text
Answer #1

17.

From the question:

if x not equal to 0

Precoditions:

(1)

if x>0

(2)

if x<0 (since x not equal ot zero dont take x as 0)

Post condition:

{y>0}

case1:

if x>0 then

let x = 1

y= 2*x = 2*1 = 2

since 2>0 the post condition y>0 is true.

case2:

else // it indicatesif x<0

let x = -3

y= (-2)*x = 2*-(-3) = 6

since 6>0 the post condition y>0 is true.

Hence proved

18.

From the question:

if x not equal to 0

Precoditions:

(1)

if x>0 (since x not equal ot zero dont take x as 0)

(2)

if x<0

Post condition:

result is |x|

case1:

if x>0 then

let x=1

abs = x = 1

since x = abs = |x| = 1 the post condition |x| is true.

case2:

else // it indicatesif x<0

let x=-1

abs = -x = -(-1) = 1

since x = -1 and abs = |x| = 1 the post condition |x| is true.

Hence proved

Any doubts leave a comment. Please Rate My Answer

Add a comment
Know the answer?
Add Answer to:
17. hy the correctness of the following program segment with the precondition and postcondition shown {x60...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT