Fibonacci Sequence

tk.unlimited

Active member
Joined
Apr 2, 2005
Messages
27
Programming Experience
1-3
Hey All

I need to display the fibonacci sequence in a label, repeating it N times where N is the number entered in the textbox.
Neone know how to code it?

ALSO anyone know how to display the numerical series of the number - that is all the numbers up to that number added together. EG Series of 5 is (1+2+3+4+5)
Thanks
Tk Unlimited
 
For the answer use:
VB.NET:
		Dim numlng As Integer = 5
		Dim total As Integer
		Dim x As Integer
		For x = 1 To numlng
			total += x
			MsgBox(total)
		Next
		TextBox1.Text = total

For the equation use:
VB.NET:
		Dim numlng As Integer = 5
		Dim equation As String
		Dim x As Integer
		For x = 1 To numlng
			equation &= x & "+"

		Next
		TextBox2.Text = Replace(equation, numlng & "+", numlng)
 
I think you can find that in many sites. Hope this helps:
VB.NET:
[color=Blue]Private Function[/color] fibo([color=Blue]ByVal [/color]n [color=Blue]As Long[/color]) [color=Blue]As Long[/color]
	[color=Blue]If [/color]n <= 1 [color=Blue]Then[/color]
		[color=Blue]Return [/color]n
	[color=Blue]Else[/color]
		[color=Blue]Return [/color]fibo(n - 1) + fibo(n - 2)
	[color=Blue]End If[/color]
[color=Blue]End Function[/color]

However, if your n is bigger than 30, better convert this to a For..Next loop.
 
Back
Top