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!
4 1516
Please guys I really really need your help... Whenever I use For & Next, things get messed up. So I don't know what else to use in order to loop the whole thing... Please help me! :(
Search for vb6 decimal binary with your friends (yahoo, google, ask, answers, bing) as I know there is code out there to do this conversion...
Good Luck
@vb5prgrmr
Thank you for the reply! I have been doing so for like hours already and the codes are really complicated compared to what I have done... >_<
dear,
Just do a For...next from 1 to K , check If round number and enter in a counter with "counter=counte r+1" each time you have a round number.
send a msgbox with ("THERE ARE " & counter & " ROUND NUMBERS LESS THAN OR EQUAL TO " & k)
br,
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Bart Plessers \(artabel\) |
last post by:
Hello,
I have an asp script that lists the files in a directory:
CurrentPATH = "c:\temp\"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(CurrentPATH)
Set oFolderContents = oFolder.Files
For Each oFileItem in oFolder.Files
.....
|
by: Steven |
last post by:
Hi,
I am trying to find out how many digits there are in a given number.
The macro listed below works fine when applied to an INT, however when
doing Doubles with numbers > then a billion ?? It stops working.
Anyone any idea's ?
Thankx !
|
by: Lance Hoffmeyer |
last post by:
Is there an easy way to round numbers in an array?
I have
Test =
and want to round so the values are
print Test
|
by: Henrootje |
last post by:
I am looking for a way to round down the results of a calculation in a
query
f.e.:
in a query this calculation is performed:
a/b = c
5/3 = 1,666666667
|
by: Samuel |
last post by:
Hi
I am looking for a method that rounds numbers to a specified number of
decimal places for example if I pass 2.455 it will return 2.46
Thank you,
Samuel
| |
by: slider |
last post by:
hey all, i have a set of numbers which looks like this
21551878283310414135344613310414135344613310468612568833104686125688331043180057716331044879441661331045148067733104487944166133104
within this block of numbers are the numbers 33104 repeated where necessary. This is practically like a space or a comma to space out the numbers.
I...
|
by: Aussie Rules |
last post by:
Hi,
Whats the easiest way to round numbers up.
For example, a calculation that results in a value of 1.3 will round to 1,
and a calculation that results in 1.8 will round to 2.
My issue that I want the 1.3 to always round up to 2, as to round down to 1
results is short supply of stock, which is worse than an over supply.
|
by: =?Utf-8?B?RWR3aW4=?= |
last post by:
What I am trying to do is come up with a way to determine how many unique
extensions there are within a directory and its sub directories. Within the
loop that recurses root folder, I am attempting to use a SortedList. Below
is the code:
private System.Collections.SortedList _ArrayListOfExtensions = new
SortedList(new...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |