36.6k views
5 votes
This exercise contains a while loop and a predicate. loop: while (m ≥ 0 and m ≤ 100) m := m + 4 n := n − 2 end while predicate: m + n is odd Fill in the blanks to show that if the predicate is true before entry to the loop, then it is also true after exit from the loop. Suppose m + n is odd before entry into the loop. Suppose m + n is odd before entry into the loop. Let new + new denote the values of m and n after exit from the loop. Find and simplify an expression for new + new in terms of m and n.

User Shivana
by
8.5k points

1 Answer

4 votes

Answer:

m' + n' = m + n + 2

Explanation:

We are told that m + n is odd before entry into the loop. So let, P(q) be m + n is even on qth iteration of the while loop

Our basis step will be q = 0.

So, let P(k) be true and we can say that m + n is odd on the kth iteration of the while loop

Now, we need to prove that P(k + 1) is true.

Thus, on the (k + 1)th iteration, m is increased by 4 and n is decreased by 2.

Let's call the new values m' and n'.

So, m' = m + 4 and n' = n - 2

Thus, m' + n' = m + 4 + n - 2 = m + n + 2

User UndefinedBehavior
by
8.0k points

No related questions found

Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.

9.4m questions

12.2m answers

Categories