The following algorithm is to be used on different numbers. (The function INT gives the integer part of any number, for example, INT(2.5) = 2.)
The following algorithm is to be used on different numbers. (The function
INT gives the integer part of any number, for example, INT(2.5) = 2.)
LINE 10 INPUT N
LINE 20 LET K = 0
LINE 30 LET A = N – 2 * INT (N /2)
LINE 40 LET K = K + 1
LINE 50 PRINT A
LINE 60 LET N = INT (N /2)
LINE 70 IF N > 0 THEN GOTO LINE 30
LINE 80 END
(a) Show that, if the input value of N is 5, then the algorithm will print 1, 0, 1. +17 points
____N____ ____K____ ___A____(Print)___
LINE 10 ________________________________________________
LINE 20 ________________________________________________
LINE 30 ________________________________________________
LINE 40 ________________________________________________
LINE 50 ________________________________________________
LINE 60 ________________________________________________
LINE 70 ________________________________________________
LINE 80 ________________________________________________
(b) Trace the algorithm in the case where the input value of N is 11. +10 points
____N____ ____K____ ___A____(Print)___
LINE 10 ________________________________________________
LINE 20 ________________________________________________
LINE 30 ________________________________________________
LINE 40 ________________________________________________
LINE 50 ________________________________________________
LINE 60 ________________________________________________
LINE 70 ________________________________________________
LINE 80 ________________________________________________
(c) Find the final value of K in the case where the input value of N is 40. +13 points
____N____ ____K____ ___A____(Print)___
LINE 10 ________________________________________________
LINE 20 ________________________________________________
LINE 30 ________________________________________________
LINE 40 ________________________________________________
LINE 50 ________________________________________________
LINE 60 ________________________________________________
LINE 70 ________________________________________________
LINE 80 ________________________________________________