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

The following pseudocode is intended to count the number of digits in the positi

ID: 3745315 • Letter: T

Question

The following pseudocode is intended to count the number of digits in the positive integer n count temp n While temp > 10 Increment count Divide temp by 10.0 Trace the pseudocode for n 123, n 100, and n- 3. What errors do you find, and how do you fix the code? The code is wrong for all inputs. The loop condition should be temp F10 The code is wrong for inputs that are divisible by ten. The loop condition should be temp I0 The code is wrong for inputs that are less than ten. The loop condition should be temp > 0. There are no errors

Explanation / Answer

Answer: B

The code is wrong for inputs that are divisible by ten. The loop conditions sholuld be temp>=10

Trace:

for input 123:

count is 1 here

while(123>10) =>True

count will be 2

123/10=> 12

while(12>10) True

count is 3

12/10 =>2

while(2>10) False

at the end count is 3 which is correct

but in case of input 100

count is 1 here

while(100>10)=> True

count will be 2.

100/10 => 10

And even though 10 is 2 digit number it will not be considered as one digit.

if we include = in while condition the output will be corrected.