|
-
Feb 16th, 2004, 09:36 PM
#1
Thread Starter
New Member
How do you do these?????
How would I program these in MS Visual studio .net:
1) DivisibleBy: Receives two positive integers. The first integer must be greater than the second. Return a zero-length string if this is not the case or if the integers are less than zero. Otherwise, the procedure will return a string containing all the numbers between 0 and the first parameter that are divisible by the second parameter with each number separated by a comma. For instance, if the arguments are 20 and 3 then the return string would be "3,6,9,12,15,18".
and this...
2) NumberOfTimes: Receives two strings and returns an integer representing the number of times the first string appears inside the second string. You cannot use the split method of the string object; however, the SubString and IndexOf methods should be quite helpful.
-
Feb 16th, 2004, 09:50 PM
#2
First, post in the right Forum (.Net)
Second, pay attention to what the Moderator has already told you; and make a start on your own Assisgnment. When you get stuck on something then ask!
-
Feb 16th, 2004, 09:57 PM
#3
The picture isn't missing
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Feb 16th, 2004, 10:03 PM
#4
His first thread was in General Vb and I moved it to .Net. I assume he couldn't find it and so he reposted. BTW, I'm also moving this one although I should probably delete it.
-
Feb 17th, 2004, 02:36 AM
#5
Re: How do you do these?????
Originally posted by alejandrman
How would I program these in MS Visual studio .net:
1) DivisibleBy: Receives two positive integers. The first integer must be greater than the second. Return a zero-length string if this is not the case or if the integers are less than zero. Otherwise, the procedure will return a string containing all the numbers between 0 and the first parameter that are divisible by the second parameter with each number separated by a comma. For instance, if the arguments are 20 and 3 then the return string would be "3,6,9,12,15,18".
and this...
2) NumberOfTimes: Receives two strings and returns an integer representing the number of times the first string appears inside the second string. You cannot use the split method of the string object; however, the SubString and IndexOf methods should be quite helpful.
1. 20 is not divisible by three... I think you meant factors of second input that are less than or euqal to first input.
Anyway to get the factors, eg 20 has 2x2x5
a) Repeatedly determine divisibility by (2n-1) where:
n >= 2, start with divisible by 3
Every time the number is divisible by 2n-1, store the value of n
then start next divisibility loop at the stored value of n and update X to X=X/(2n-1)
After doing that, you should get divisibility for all prime numbers excluding 2 eg 3, 5, 7, 11 with repetitions if applicable eg 3x3... note although you'll check at 9 (for simplicity just increment, dont check for factors of 3, 5, etc in 2n -1) it will not be returned as a factor since you already repeatedly dividing by 3 (stored n) until it is no longer divisible by 3 and n is incremented.
b) After doing divisibility by odd, repeatedly divide by 2 to get number of factors of 2.
c) If no factors are returned, then factors are 1 and the number itself
2) If a substring exists and its position determined, remove the string and check again if another substring exists..
Last edited by leinad31; Feb 17th, 2004 at 02:41 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|