Fibonacci series using VB.NET

In Fibonacci series each subsequent number is the sum of the previous two integer value.
  • 19212
 

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.

pinball5.GIF.jpg

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

1.gif

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

2.gif

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.