Calculating factorials using recursion : Function Recursive « Language Basics « VB.Net






Calculating factorials using recursion

Calculating factorials using recursion
Imports System

Public Class MainClass

    Shared Sub Main(ByVal args As String())
      Dim value As Integer = Convert.ToInt32(12)
      Dim i As Integer

      For i = 0 To value
         Console.WriteLine( i & "! = " & Factorial(i) & vbCrLf )
      Next

    End Sub

   ' recursively generates factorial of number
   Shared Function Factorial(ByVal number As Long) As Long

      If number <= 1 Then ' base case
         Return 1
      Else
         Return number * Factorial(number - 1)
      End If

   End Function ' Factorial
End Class

           
       








Related examples in the same category

1.Function RecursiveFunction Recursive
2.Display directories on your drive recursivelyDisplay directories on your drive recursively
3.Recursive Function DemoRecursive Function Demo