[Solved] Number of terms in this code series? [closed]


It is log2 n, that is the number of binary bits (or the rank of the highest 1 bit) in the binary representation of n

And you made a typo, you probably mean

 for(i=n,j=0 ; i>0 ;  (i/=2), (j+=i));

So you start with i==n then you halve it till 0 is reached (hence the log2 n number of loops).

3

solved Number of terms in this code series? [closed]