Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following algorithm: R = 46; Q = 0; D = 6; as long as R is greater

ID: 3541913 • Letter: C

Question

Consider the following algorithm:


R = 46;

Q = 0;

D = 6;

as long as R is greater than or equal to D do

{

      R = R - D;

      Q = Q + 1;

}



a. Trace out each step as begun below for you:

    Initially:         R = 52 Q = 0

    After 1 step: R =       Q =

    After 2 step: R =       Q =

.......(use as many rows as needed)


b. what does this algorithm accomplish? Explain the result of the algorithm(ie the relationship between R, Q, and D) WITHOUT simply explaining or restating the algoritm in part a.

Explanation / Answer

a)

Initially: R = 52 Q = 0

After 1 step: R = 46 Q = 1

After 2 step: R = 40 Q = 2

After 3 step: R = 34 Q = 3

After 4 step: R = 28 Q = 4

After 5 step: R = 22 Q = 5

After 6 step: R = 16 Q = 6

After 7 step: R = 10 Q = 7

After 8 step: R = 4 Q =8


b) The algorithm accomplishes the quotient when R is divided by D
so at the and, when algorithm terminates, Q = R / D

At each step, we are incrementing Q by 1 and decrementing R by D. This is what division means.


So relationship between R, Q and D is

Q = R/D

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote