NOTE: I am using Excel VBA.
Please help me program the following problem:
A positive integer n is said to be a ROUND NUMBER if the binary representation of n has as many or more zeros as ones. For example:
The integer 9, written in binary form, is 1001. 1001 has two zeros and two ones; thus 9 is a ROUND NUMBER.
The integer 26, written in binary form, is 11010. 11010 has two zeros and three ones; thus 26 is not a ROUND NUMBER.
Write a program which will accept a positive integer k as input and print out the numbers of ROUND NUMBERS less than or equal to k in the following format:
THERE ARE XXX ROUND NUMBERS LESS THAN OR EQUAL TO K
Sample Run
Input: K= 10
Output: THERE ARE 5 ROUND NUMBERS LESS THAN OR EQUAL TO 10.
Input: K= 100
Output: THERE ARE 47 ROUND NUMBERS LESS THAN OR EQUAL TO 100.
I have already managed to convert decimal to binary and to get the number of zeroes and number of ones. I just can't figure out how to do the following: 1) Do the entire thing for the whole range. Example, how do I get the binary equivalent of 5, 4, 3, 2, and 1 simultaneously? I can only get the binary equivalent of one decimal at a time. I've been doing this since last night... The deadline for this is later at 11:59 PM. Please do help me... Thank you very much!
P.S. Please leave me a private message if you want to see the codes that I have managed to do so far. I read in your site that I should not post the codes that I have done so as to prevent plagiarism. Thank you!