How to resolve the algorithm Fibonacci sequence step by step in the Metafont programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Fibonacci sequence step by step in the Metafont 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 Metafont programming language

Source code in the metafont programming language

vardef fibo(expr n) =
if n=0: 0
elseif n=1: 1
else:
  fibo(n-1) + fibo(n-2)
fi
enddef;

for i=0 upto 10: show fibo(i); endfor
end

  

You may also check:How to resolve the algorithm Loops/Infinite step by step in the Lang programming language
You may also check:How to resolve the algorithm Loop over multiple arrays simultaneously step by step in the Maple programming language
You may also check:How to resolve the algorithm Floyd's triangle step by step in the OxygenBasic programming language
You may also check:How to resolve the algorithm Consecutive primes with ascending or descending differences step by step in the Julia programming language
You may also check:How to resolve the algorithm AKS test for primes step by step in the Idris programming language