Suite de Fibonacci
Description du code
Exemple de méoïsation en PascalCode source ou contenu du fichier
Code Pascal (Suite de Fibonacci ) (35 lignes)
program fibonacci-memo; cons undef = -1; {valeur qui n'est jamais employee et qui signifie une valeur non definie} cons maxIndice = 20; var memoArray : packed array[0..maxIndice] of integer; function fibonacci(var n : integer) : integer; {Pre: 0 <= n <= maxIndice} begin if n < 2 then fibonacci := n; else fibonacci := fibonacciMemo(n-1) + fibonacciMemo(n-2); end; function fibonacciMemo(var n : integer) : integer; {Pre: 0 <= n <= maxIndice} begin if memoArray[n] = undef then memoArray[n] := fibonacci(n);{il est necessaire de calculer la valeur} fibonacciMemo := memoArray[n];{la valeur est deja calculee} end; {main program} begin var i : integer; var j : integer; j:=20; for i:=0 to maxIndice do memoArray[i]:=undef; writeln('Fibonacci(', j, ') = ', fibonacci(j)); end.
Autres extraits de codes en Pascal
- Merge Sort Exemple de tri par fusion
- Selection Sort Exemple de tri par sélection
- Suite de Fibonacci Exemple de récursion en Pascal
- Suite de Fibonacci Exemple de méoïsation en Pascal
- Tous les extraits
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 05/10/2009, last modified the 28/10/2018
Source of the printed document:https://www.gaudry.be/en/sniplet-rf-pascal/fibonacci-memo.pas.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.