How to resolve the algorithm Fibonacci sequence step by step in the ERRE programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Fibonacci sequence step by step in the ERRE programming language
Table of Contents
Problem Statement
The Fibonacci sequence is a sequence Fn of natural numbers defined recursively:
Write a function to generate the nth Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow and are mostly used as an exercise in recursion). The sequence is sometimes extended into negative numbers by using a straightforward inverse of the positive definition: support for negative n in the solution is optional.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Fibonacci sequence step by step in the ERRE programming language
Source code in the erre programming language
!-------------------------------------------
! derived from my book "PROGRAMMARE IN ERRE"
! iterative solution
!-------------------------------------------
PROGRAM FIBONACCI
!$DOUBLE
!VAR F1#,F2#,TEMP#,COUNT%,N%
BEGIN !main
INPUT("Number",N%)
F1=0
F2=1
REPEAT
TEMP=F2
F2=F1+F2
F1=TEMP
COUNT%=COUNT%+1
UNTIL COUNT%=N%
PRINT("FIB(";N%;")=";F2)
! Obviously a FOR loop or a WHILE loop can
! be used to solve this problem
END PROGRAM
You may also check:How to resolve the algorithm Logical operations step by step in the Neko programming language
You may also check:How to resolve the algorithm Pernicious numbers step by step in the Groovy programming language
You may also check:How to resolve the algorithm Factors of an integer step by step in the Logo programming language
You may also check:How to resolve the algorithm LZW compression step by step in the EMal programming language
You may also check:How to resolve the algorithm Loops/Do-while step by step in the R programming language