Fibonacci number/de: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | Die Fibonacci-Zahlen-Folge ist eine Reihe von Zahlen: | |
| 2 | 2 | ||
| 3 | - | ||
| 3 | + | ```text | |
| 4 | + | 0, 1, 1, 2, 3, 5, 8, 13, 21, ... | |
| 5 | + | ``` | |
| 4 | 6 | ||
| 5 | 7 | Die Idee dahinter ist, die zwei vorhergehenden Zahlen zu addieren um die nächste zu erhalten. Sie benannt nach [Leonardo Fibonacci](https://de.wikipedia.org/wiki/Leonardo_Fibonacci) einem Rechengelehrten (heute würde man sagen Mathematiker) aus Pisa. Bekannt war die Folge lt. Wikipedia aber schon in der Antike bei den Griechen und Indern. | |
| 6 | 8 | ||
| 7 | 9 | ## rekursive Art | |
| 8 | 10 | ||
| 9 | 11 | ``` pascal | |
| 10 | 12 | ||
| 11 | 13 | function FibonacciNumber( n : integer ): integer; | |
| 12 | 14 | begin | |
| 13 | 15 | if n > 1 then | |
| 14 | 16 | result := ( FibonacciNumber( n - 1 ) + FibonacciNumber( n - 2 ) ) | |
| 15 | 17 | else if n = 0 then | |
| 16 | 18 | result := 0 | |
| 17 | 19 | else | |
| 18 | 20 | result := 1; | |
| 19 | 21 | end; | |
| 20 | 22 | ``` | |
| 21 | 23 | ||
| 22 | 24 | ## iterative Art | |
| 23 | 25 | ||
| 24 | 26 | Diese ist vorzuziehen. | |
| 25 | 27 | ||
| 26 | 28 | ``` pascal | |
| 27 | 29 | function Fibonacci(n: Integer): Integer; | |
| 28 | 30 | var | |
| 29 | 31 | i, u, v, w: Integer; | |
| 30 | 32 | Begin | |
| 31 | 33 | if n <= 0 then | |
| 32 | 34 | Result := 0 | |
| 33 | 35 | else if n = 1 then | |
| 34 | 36 | Result := 1 | |
| 35 | 37 | else | |
| 36 | 38 | begin | |
| 37 | 39 | u := 0; | |
| 38 | 40 | v := 1; | |
| 39 | 41 | for i := 2 to n do | |
| 40 | 42 | begin | |
| 41 | 43 | w := u + v; | |
| 42 | 44 | u := v; | |
| 43 | 45 | v := w; | |
| 44 | 46 | end; | |
| 45 | 47 | Result := v; | |
| 46 | 48 | end; | |
| 47 | 49 | End; | |
| 48 | 50 | ``` | |
| 49 | 51 | ||
| 50 | 52 | ## Siehe auch ... | |
| 51 | 53 | ||
| 52 | 54 | - [Some assembly routine which uses the C calling convention that calculates the nth Fibonacci number](http://www.freepascal.org/docs-html/prog/progsu151.html) | |
| 53 | 55 | - [[Solution 3|Tao Yue Solution to Fibonacci Sequence Problem]] | |
| 54 | 56 | - [Wikipedia: Fibonacci-Folge](https://de.wikipedia.org/wiki/Fibonacci-Folge) | |
| 55 | 57 | ||
| 56 | 58 | --- | |
| 57 | 59 | *From the Free Pascal wiki, page "Fibonacci number/de", as it stood on 2020-01-12 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).* |
