Results 1 to 5 of 5

Thread: How do you do these?????

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    3

    Angry 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.

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    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!

  3. #3
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Originally posted by BuggyProgrammer
    and don't post twice... http://www.vbforums.com/showthread.p...hreadid=279178
    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.

  5. #5
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    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
  •  



Click Here to Expand Forum to Full Width