232k views
4 votes
Consider the following pseudocode: procedure (n int) while n>0 n := floor (n/7) print n On input n = 45 the output to the code is A. 5 0 B. 6 10 C. 60 D. 5 1 E. 35 7 1 0 F. none of (A.) (E.)

User Burferd
by
8.2k points

1 Answer

4 votes

Answer:

Step-by-step explanation:

To determine the output of the given pseudocode procedure for input n = 45, let's follow the steps of the procedure:

Initialize n = 45.

Enter the while loop.

Check if n > 0. Since 45 is greater than 0, continue.

Update n by taking the floor of n divided by 7: n = floor(45/7) = 6.

Print the value of n, which is 6.

Continue to the next iteration of the while loop.

Check if n > 0. Since 6 is greater than 0, continue.

Update n by taking the floor of n divided by 7: n = floor(6/7) = 0.

Print the value of n, which is 0.

Continue to the next iteration of the while loop.

Check if n > 0. Since 0 is not greater than 0, exit the while loop.

Therefore, the output of the code for input n = 45 is:

6 0

The correct answer is A. 6 0.

User Flatlineato
by
7.6k points