Question: 8 The following algorithm calculates a number known as the 'digital root' of a positive integer. 1. Input a positive integer n 2. d-number of
8 The following algorithm calculates a number known as the 'digital root' of a positive integer. 1. Input a positive integer n 2. d-number of digits in n 3. While d> 1 do 3.1. n sum of the digits of n 3.2. d number of digits in n 4. Output n (a) Trace the algorithm when 8678 is input. (b) List all the possible values that the output of the algorithm could take. 9 Consider the following sequence of steps: 1. Input a non-negative integer n 2. ito 3. While n is even do 3.1. nen/2 3.2. ii +1 4. Output i (a) What is the output when 12 is input? (b) What is the output when any odd number is input? (c) What happens when 0 is input? (d) Is this sequence of steps an algorithm
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
