Question

Programming languages question (Please help if you can) Prove (or disprove) that the following pre-post form...

Programming languages question (Please help if you can)

Prove (or disprove) that the following pre-post form is correct

{ x > 0 }

if (x > 0)

y = 2 * x + 1;

else

y = x + 4;

{ y < 3 }

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

In above problem there is two condition :-
pre condition :- x > 0 /* it means that given input which will be x and x>0.*/
post condition :- y < 3 /* after program will finish it's execution if it is correct then it will meet the condition */

{ x > 0 }
if(x>0)
y=2*x+1;
else
y=x+4;
{ y < 3 }


-> in above example we will give some input and check wether the program is correct or not.
input :- 1 (x=1>0)
output :- 3 (y=3!<3)

here we give input (1) which satisfy the pre condition then y will become 3 which will not satisfy post condition. so, we can say that this problem is not correct. so it is disproved that above form is correct.


Add a comment
Know the answer?
Add Answer to:
Programming languages question (Please help if you can) Prove (or disprove) that the following pre-post form...
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