Results 1 to 10 of 10

Thread: [RESOLVED] recursion code , rewriting?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    18

    Resolved [RESOLVED] recursion code , rewriting?

    sorry if i have posted in wrong place, i dont where else it will fit in

    here is example of mod:
    17 MOD 7 is 3
    72 MOD 15 is 12

    i have the following code:

    FUNCTION Curiosity(X:Integer;Y:Integer):Integer;
    IF Y = 0 THEN
    Curiosity = X
    ELSE
    Output Y and (X MOD Y)
    Curiosity = Curiosity(Y,X MOD Y)
    ENDIF
    END Curiosity

    i have to rewrite the above as an iterative algorithm not as recursive.
    i am puzzled and would greatly appreciate if someone could attempt this. however i only require it to be small, max about 20 lines, and only need it to use basic vb language, such as the following:

    for and next loop, do while, if and end if, mod, etc

    once again, i would really appreciate your effort to help me.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: recursion code , rewriting?

    If it is VB related it should go in ClassicVb.

    If it is VBA related it should go in Office Development.

    Let me know which it is an I will move this thread to its proper location for you.

    Thanks.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: recursion code , rewriting?

    kazoo: Please check your private messages.
    Last edited by Hack; Apr 27th, 2006 at 01:09 PM.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: recursion code , rewriting?

    In so far as my inquires have gone unanswered, I'm going to make an educated guess based on prior threads from this member, that this is an Excel VBA question.

    Moved from the CodeBank.

  5. #5
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: recursion code , rewriting?

    What is the purpose of this function?
    What value is it supposed to return? Say for an input value set of 72,15
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  6. #6
    Lively Member New2vba's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    95

    Re: recursion code , rewriting?

    This is another example from a test paper (appeared in another post).

    See page 7 of the attached.

    http://www.ocr.org.uk/OCR/WebSite/Da...Level93039.pdf
    "Those things we must learn to do, we must learn by doing" (or hope somebody else will take pity and help out )

  7. #7
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: recursion code , rewriting?

    Thanks, I'll be removing my subscription to this thread then....
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  8. #8
    Addicted Member
    Join Date
    Jan 2006
    Location
    Montreal, Canada
    Posts
    152

    Re: recursion code , rewriting?

    Have fun!!!!!


    VB Code:
    1. Public Function Curiosity(X As Integer, Y As Integer) As Integer
    2. Dim temp As Integer
    3. Do While Y >= 0
    4.     If Y = 0 Then
    5.         Curiosity = X
    6.         Exit Do
    7.     Else
    8.         MsgBox "Value of Y :" & Y & " " & "Value of X MOD Y :" & (X Mod Y)
    9.         temp = Y
    10.         Y = X Mod Y
    11.         X = temp
    12.     End If
    13. Loop
    14. End Function

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    18

    Re: recursion code , rewriting?

    thank you very much for your help and for putting it in simplistic terms.

  10. #10
    Addicted Member
    Join Date
    Jan 2006
    Location
    Montreal, Canada
    Posts
    152

    Re: recursion code , rewriting?

    my pleasure, then you can mark the thread as resolved.

    Thread Tool on upper right

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