Today, I'm going to give you a code to add a requested number of Fibonacci numbers into a ListBox.
Components needed :
Let the Fibonacci Sequence be : 1, 1, 2, 3, 5, 8, 13, 24, ...
Let n be the number of the Fibonacci numbers to be added to the list List1.
Let l be the number of loops to be conducted.
Private Sub Command1_Click()
Dim a, b, c As Double
Dim l, n As Integer
a = 0
b = 1
n = Val(Text1.Text)
For l = 1 To n
a = b
b = c
c = a + b
List1.AddItem (c)
Next
End Sub
The idea here is to swap between a,b, and c to obtain the next number in the Fibonacci sequence.
It's as simple as that.
Here's a preview of what it looks like:
Note:
The Fibonacci sequence is an interesting set of numbers. You might want to do some research on it.
Happy Coding,
Cyber Frost
Components needed :
- 1 List Box
- 1 Text Box
- 1 Label
- 1 Button
Let the Fibonacci Sequence be : 1, 1, 2, 3, 5, 8, 13, 24, ...
Let n be the number of the Fibonacci numbers to be added to the list List1.
Let l be the number of loops to be conducted.
Private Sub Command1_Click()
Dim a, b, c As Double
Dim l, n As Integer
a = 0
b = 1
n = Val(Text1.Text)
For l = 1 To n
a = b
b = c
c = a + b
List1.AddItem (c)
Next
End Sub
The idea here is to swap between a,b, and c to obtain the next number in the Fibonacci sequence.
It's as simple as that.
Here's a preview of what it looks like:
Note:
The Fibonacci sequence is an interesting set of numbers. You might want to do some research on it.
Happy Coding,
Cyber Frost
No comments:
Post a Comment