Interactive PowerBasic Forum

IT-Consultant: Charles Pegge => OxygenBasic Examples => Topic started by: Frank BrĂ¼bach on April 02, 2024, 08:25:04 PM

Title: Function qt
Post by: Frank BrĂ¼bach on April 02, 2024, 08:25:04 PM
Hi all hi Charles

IS this Kind of function structure possible in oxygen?



Function factorial(x As Integer) As Integer
    ' This is a recursive function
    ' to find the factorial of an integer

    If x = 1 Then
        factorial = 1
    Else
        'factorial = x * factorial(x - 1)
        return x * factorial(x-1) 
    End If
End Function

print factorial(2)

Dim num As Integer
    num = 3

Print "The factorial of " + num  + " is "  ''+ str(factorial(num) )
Title: Re: Function qt
Post by: Charles Pegge on April 02, 2024, 08:51:17 PM
Almost:

Function factorial(x As Integer) As Integer
    ' This is a recursive function
    ' to find the factorial of an integer

    If x <= 1 Then
        return 1
    Else
        'factorial = x * factorial(x - 1)
        return x * factorial(x-1)
    End If
End Function

print factorial(4) '24