Algorithm Generate Fibonacci Series in VB.NET

A Sequence of numbers in which 1 appears twice as the first two numbers, and every subsequent number is the sum of two preceding numbers: 1, 1, 2, 3, 5, 8, 13....and so on is called Fibonacci Series.
• 4207

The Fibonacci Series is a sequence of numbers first created by Leonardo Fibonacci (fi-bo-na-chee) in 1202 Sequence of numbers in which 1 appears twice as the first two numbers, and every subsequent number is the sum of two preceding numbers: 1, 1, 2, 3, 5, 8, 13....and so on. As it continues, the ratio between any number and its successor approaches the ratio of golden section (1:1.618). the most spectacular examples of the Fibonacci Series in nature is in the head of the sunflower. Scientists have measured the number of spirals in the sunflower head. They found, not only one set of short spirals going clockwise from the centre, but also another set of longer spirals going anti clockwise.

The Fibonacci Series is as follows 0 , 1 , 1 , 2 , 3 , 5 , 8 , â€¦

The property of this series is that any given element in the series after the third element is the sum of its first and second predecessor. For example, consider 8. Its first and second predecessors are 5 and 3. Therefore, 5 + 3 = 8. Consider 3. Its first and second predecessors are 2 and 1. 2 + 1 = 3. The property of Fibonacci series holds.

The following is the algorithm to generate the Fibonacci series up to a given number of elements.

Algorithm : Fibonacci_Series

Input : n, the number of elements in the series

Output : fibonacci series upto the nth element

Method

a = -1
b = 1
for(i=1 to n in steps of +1 do)
c = a + b
display 'c'
a = b
b = c
end_for

Algorithm ends

Example

Namespace DBExample
Class Program
Private Shared Sub Main(ByVal args As String())
Dim i As Integer, j As Integer
i = -1
j = 1
Dim n As Integer
n = 20
Dim fib As Integer = 1
While fib <= n
fib = i + j
i = j
j = fib
Console.WriteLine(fib)
End While
End Sub
End
Class
End
Namespace

Summary

The above article show how to get Fibonacci Series, hope you will learn and use this concept as you required.