Neon32
- 68
- 1
It would be much appreciated if you could show me how to do recursive tracing for this method.
Last edited:
BvU said:What's recursive in this method ?
Did you try typing it in and see what it does ?
Is this homework ?
I see. Maybe I misunderstand 'recursive' : I then expect a call to 'mystery' inside the method.Neon32 said:1) mystery(n-1) is recursive
BvU said:Did you try typing it in and see what it does ?
BvU said:All I've left is question 2![]()
----- 6 ----------
(6 + ((4 + ((2 + ( 0
+ 1)
)
+ 3)
)
+ 5)
)
--------------------------
Sub mist(n As Integer)
If n / 2 = 0 Then
Debug.Print n
ElseIf n Mod 2 = 0 Then
Debug.Print "(" & n & " + ";
mist n - 1
Debug.Print ")"
Else
Debug.Print "(";
mist n - 1
Debug.Print " + " & n & ")"
End If
End Sub
Sub test()
Dim n As Integer
again:
n = CInt(InputBox("Give n "))
Debug.Print " "
Debug.Print " ----- " & n & " ---------- "
If n < 0 Then Exit Sub
Call mist(n)
Debug.Print " -------------------------- "
GoTo again
End Sub
No. The mystery() function is recursive because it calls itself.Neon32 said:1) mystery(n-1) is recursive
BvU didn't ask about tracing the function; he asked if you had tried typing it in and running it. Seeing what the function produces might be helpful in understanding what it does.Neon32 said:Yes I've tried to trace it and all I got was (6 + ((4 + ((2 + . I don't understand how to continue it.
----- 6 ----------
(6 + ((4 + ((2 + 1 ) + 3)) + 5))
--------------------------
Thank you :).BvU said:Didn't know that; was just trying to help. My systematic method has always been trial and error-- especially the latter.
Good luck with your exam !