Monday, May 24, 2010

Consider the following algorithm?

get I





get N





set C = N





While (C is %26gt;= 1) Do





print ‘*’





set C = C / I





End While





(end of program)





Note that “print ‘*’” simply outputs an asterisk to the screen. Also, / refers to integer division, which means the remainder is simply thrown out. How many times would this line of code be executed (or, how many asterisks would be printed to the screen), assuming that the user inputs:








i) I = 2, N = 16





ii) I = 2, N = 64





iii) I = 5, N = 625





iv) I = y, N = x (Express the answer in terms of x and y)





v)What runtime/logic error does this algorithm have which will produce an infinite loop?

Consider the following algorithm?
i) I = 2, N = 16--%26gt;4 times





ii) I = 2, N = 64 --%26gt; 6 times





iii) I = 5, N = 625 --%26gt;4 times





v)What runtime/logic error does this algorithm have which will produce an infinite loop?


It would loop infinitely when the values of L and N are 1.
Reply:consider asking your teacher.. or doing your own homework





i will give you a clue... its all to do with the





While (C is %26gt;= 1) Do





part ;-)
Reply:stop it and think for urself. I hope that u have yahoo answers when ur doing ur exam. lol


No comments:

Post a Comment