0
$\begingroup$

With "n" being any positive integer, how many times the statement of while loop will be run, related to "n" please?

while(n%2 == 0) n=n/2
$\endgroup$
0
$\begingroup$

Primes other than $2$ don't matter at all. Just try it with the numbers from $10$ through $16$ and you will probably see a pattern.

$\endgroup$
  • $\begingroup$ It will be log2(n) right? $\endgroup$ – higraphs May 8 at 2:32
  • $\begingroup$ It will be no more than that, but it could be much less. $\endgroup$ – Ross Millikan May 8 at 2:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.