30.07.2013 Views

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 6 Procedures 223<br />

23 lblResult.Text = "Fibonacci Value is " & Fibonacci(number)<br />

24 End Sub ' cmdCalculate_Click<br />

25<br />

26 ' calculate Fibonacci value recusively<br />

27 Function Fibonacci(ByVal number As Integer) As Long<br />

28<br />

29 ' check for base cases<br />

30 If number = 1 OrElse number = 0 Then<br />

31 Return number<br />

32 Else<br />

33 Return Fibonacci(number - 1) + Fibonacci(number - 2)<br />

34 End If<br />

35<br />

36 End Function ' Fibonacci<br />

37<br />

38 End Class ' FrmFibonacci<br />

Fig. Fig. 6.20 6.20 Recursively generating Fibonacci numbers (part 2 of 3).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!