Fibonacci series using VB.NET
In Fibonacci series each subsequent number is the sum of the previous two integer value.
Fibonacci series: It is mathematical function to add each previous subsequent number. In Fibonacci series each subsequent number is the sum of the previous two integer value. Suppose you have two integers value are 2 and 5 then you will get output 7, 12. See below figure to know how Fibonacci series works.
Module1.vb
Imports System.Collections.Generic
Module Module1
Sub Main()
Dim n1 As Integer
Dim n2 As Integer
n1 = 1
n2 = 1
Console.WriteLine("{0}", n1)
While n2 < 300
Console.WriteLine(n2)
n2 = n2 + n1
n1 = n2 - n1
End While
Console.ReadLine()
End Sub
End Module
Output
For your better understanding I used below code to represent how Fibonacci series works.
Module2.vb
Module Module1
Sub Main()
Dim n1 As Integer
Dim n2 As Integer
n1 = 1
n2 = 1
Console.WriteLine("n1 is {0}", n1)
Console.WriteLine("n2 is {0} ", n2 & vbLf)
While n2 < 500
n2 = n2 + n1
Console.WriteLine("n2 is n2+n1=" & n2)
n1 = n2 - n1
Console.WriteLine("n1 is n2-n1=" & n1 & vbLf)
End While
Console.ReadLine()
End Sub
End Module
Output