The numbers listed in ascending order will always follow a pattern. 111 ... 1 (n digits, all 1's with no 0's between) 1011 ... 1 (n+1 digits, all 1's except a 0 in second from high order bit). 1101 ... 1 (n+1 digits, all 1's except a 0 in third from high order bit)
The n'th element of this series will always be 111 .. 01 (n+1 digits, all 1's except a 0 in the second from lowest order bit). For example if n=4, we have 01111 10111 11011 11101 So the number you want is 11101. The value of this in general is 2^(n+1) - 3. For our example n=4, this is 2^5-3 = 29 = 11101_2. It's pretty easy to give an algorithm that computes 2^(n+1) - 3. I'll let you do that. On Sep 24, 8:37 am, amit <amitjaspal...@gmail.com> wrote: > There is a sequence of increasing numbers that have the same number of > binary 1s in them. Given n, the number of 1 bits set in each number, > write an algorithm > or C program to find the n’th number in the series -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.