Sign in Join
Wiki copytemporary

Fibonacci number/fr: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Fibonacci number/fr

OldNewLine
1+# Nombre de Fibonacci
2+
3+La suite de Fibonacci est la suivante : 0, 1, 1, 2, 3, 5, 8, 13, 21, ...\
4+Chaque nombre est la somme de ses deux prédécesseurs, les deux premiers termes sont 0 et 1.
5+
6+## Méthode récursive
7+
8+``` pascal
9+function FibonacciNumber( n : integer ): integer;
10+begin
11+ if n > 1 then result := ( FibonacciNumber( n - 1 ) + FibonacciNumber( n - 2 ) )
12+ else
13+ if n = 0 then result := 0
14+ else result := 1;
15+end;
16+```
17+
18+## Méthode itérative
19+
20+Celle-ci est préférable.
21+
22+``` pascal
23+function Fibonacci(n: Integer): Integer;
24+var
25+ i,u,v,w: Integer;
26+begin
27+ if n <= 0 then
28+ exit(0);
29+ if n = 1 then
30+ exit(1);
31+ u := 0;
32+ v := 1;
33+ for i := 2 to n do
34+ begin
35+ w := u + v;
36+ u := v;
37+ v := w;
38+ end;
39+ Result := v;
40+End;
41+```
42+
43+## Voir aussi
44+
45+- [Suite de Fibonacci](https://fr.wikipedia.org/wiki/Suite_de_Fibonacci)
46+- [Some assembly routine which uses the C calling convention that calculates the nth Fibonacci number](http://www.freepascal.org/docs-html/prog/progsu151.html)
47+- [[Solution 3|Solution de Tao Yue au problème de la suite de Fibonacci]]
48+
49+---
50+*From the Free Pascal wiki, page "Fibonacci number/fr", as it stood on 2020-02-14 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history