Question: Consider the following method that divides an integer by 2: method DivideBy2(n: int) returns (x: int) ensures n % 2 == 0 => /*

Consider the following method that divides an integer by 2: method DivideBy2(n: int) returns (x: int) ensures

Consider the following method that divides an integer by 2: method DivideBy2(n: int) returns (x: int) ensures n % 2 == 0 => /* Omitted. */ ensures n % 2 == 1 ==> /* Omitted. */ /* The body of the method has also been omitted. */ The method also has a tester. Both the method and the tester verify. There are many ways to express the postcondition for DivideBy2. Which is not correct? (a) O (b) O (c) O (d) O (e) O ensures if n % 2 != 0 then n == 2*x + 1 else n == 2*X ensures n == if n % 2 ensures if n % 2 == ensures n % 2 ====> n == 2*x && n % 2 == 1 ==> n == 2*x + 1 == 0 then 2*x else 2*x + 1 0 then n == 2*x + n * (n % 2) else n == 2*x*(n % 2) + 1 ensures n == 2*x +n % 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

the option that is ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!