[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.
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. :)
Re: recursion code , rewriting?
kazoo: Please check your private messages.
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.
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
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
Re: recursion code , rewriting?
Thanks, I'll be removing my subscription to this thread then....
Re: recursion code , rewriting?
Have fun!!!!!
VB Code:
Public Function Curiosity(X As Integer, Y As Integer) As Integer
Dim temp As Integer
Do While Y >= 0
If Y = 0 Then
Curiosity = X
Exit Do
Else
MsgBox "Value of Y :" & Y & " " & "Value of X MOD Y :" & (X Mod Y)
temp = Y
Y = X Mod Y
X = temp
End If
Loop
End Function
Re: recursion code , rewriting?
thank you very much for your help and for putting it in simplistic terms.
Re: recursion code , rewriting?
my pleasure, then you can mark the thread as resolved.
Thread Tool on upper right