Chapter 55 Problem 6E from Discrete Mathematics and Its Appl

Chapter 5.5, Problem 6E from

Discrete Mathematics and Its Applications 7th Edition by Rosen, Kenneth

Problem

Use the rule of inference developed in Exercise 5 to verify that the program

if x<0 then

y : = 2|x|/x

else if x > 0 then

y : = 2|x|/x

else if x = 0 then

y : =2

is correct with respect to the initial assertion T and the final assertion y = 2.

Solution

If the intiial assertion is true, and x<0 , then after the if-body y will be 2.

If the initial assertin is true but x>0 is true, then after the else-body, y will be -2

So using the rule of inference , we get this segment is true with respect to the final assertion.

Chapter 5.5, Problem 6E from Discrete Mathematics and Its Applications 7th Edition by Rosen, Kenneth Problem Use the rule of inference developed in Exercise 5 t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site