Problem

One way to compute the quotient and remainder of two numbers num and den is to use repeate...

One way to compute the quotient and remainder of two numbers num and den is to use repeated subtraction as shown in the following code:

int q = 0; // the quotient

int rein = num; // the remainder

while (rem >= den) {

rem >= den) {

rem = rem- den;

q++;

} // end while

The invariant for this code is

rem >= 0 and

num = q * den + rem

For the values nurn = 17, den = 4, prove that the invariant is true before the loop begins, after each iteration (pass) of the loop, and when the loop terminates by compledng the following table (you may not need all passes shown), lhe initial values are shown:

pass

q

rem

rem >= 0

num = q * den + rem

initially

1

2

3

4

5

0

 

 

 

 

 

17

 

 

 

 

 

true

 

 

 

 

 

17 = 0 * 17 + 17, true

 

 

 

 

 

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 2
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