Search the Community
Showing results for tags 'Fibonacci number sequence'.
-
This function will calculate the Finonacci number based on a decimal value. Function: ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Fibonacci ; Description ...: Calculate the Fibonacci number of a decimal value. ; Syntax ........: _Fibonacci($iIterations) ; Parameters ....: $iIterations - An integer value to iterate to. ; Return values .: Success - Fibonacci value ; Author ........: guinness & UEZ ; Link ..........: C++ example: https://en.wikipedia.org/wiki/Functional_programming#Coding_styles ; Example .......: Yes ; =============================================================================================================================== Func _Fibonacci($iIterations) $iIterations = Int($iIterations) Local $iFirst = 0, $iSecond = 1, $iSum = 0 If $iIterations > 92 Then $iSecond = 1.0 EndIf For $i = 0 To ($iIterations - 1) $iSum = $iFirst + $iSecond $iFirst = $iSecond $iSecond = $iSum Next Return $iFirst EndFunc ;==>_FibonacciFunction V3.9.9.4+ ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Fibonacci ; Description ...: Calculate the Fibonacci number of a decimal value. ; Syntax ........: _Fibonacci($iIterations) ; Parameters ....: $iIterations - An integer value to iterate to. ; Return values .: Success - Fibonacci value ; Author ........: guinness & trancexx ; Link ..........: C++ example: https://en.wikipedia.org/wiki/Functional_programming#Coding_styles ; Example .......: Yes ; =============================================================================================================================== Func _Fibonacci($iIterations) $iIterations = Int($iIterations) Local $iFirst = 0, $iSecond = ($iIterations > 92) ? 1.0 : 1, $iSum = 0 For $i = 0 To ($iIterations - 1) $iSum = $iFirst + $iSecond $iFirst = $iSecond $iSecond = $iSum Next Return $iFirst EndFunc ;==>_FibonacciExample use of Function: For $i = 0 To 20 ConsoleWrite($i & ' >> ' & _Fibonacci($i) & @CRLF) Next