?
Solved

Need Help in Recurssion

Posted on 2006-03-26
5
Medium Priority
?
195 Views
Last Modified: 2012-08-13
Hi there

I got  a problem....as follows

Function1(x as integer)

if (x>=2) then
return function1(x-1) + function1(x-2)
else
return 0
end if

i want to know how many times the function1 will call
and if possible give me some more detailed explanation about calling the function

thanks & regards
Reddy
0
Comment
Question by:maramreddy
2 Comments
 
LVL 37

Accepted Solution

by:
Harisha M G earned 252 total points
ID: 16292590
Hi,

It depends on the value of x...

When x = 2, it will get called twice
When x = 3, it will get called 2 + 1 = thrice
When x = 4, 3 + 2 = 5 times
When x = 5, 5 + 3 = 8 times
...

---
Harish
0
 
LVL 13

Assisted Solution

by:iHadi
iHadi earned 248 total points
ID: 16293064
Yes it depends on the value of x but I think the values mgh_mgharish provided

It looks like you're using vb.net (using return)

By the way its a good idea to add a counter to the function to see exactly how many times it is called:

Dim counter As Integer

Private Function Function1(x As Integer)
    If (x >= 2) Then
        Function1 = Function1((x - 1) + Function1(x - 2))
    Else
        Function1 = 0
    End If
    counter = counter + 1
End Function

Private Sub Command1_Click()
    Counter = 0
    Function1 9
    MsgBox Counter
End Sub
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month14 days, 23 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question