Sign in Join
Wiki copytemporary

Fibonacci number/de: what changed

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

OldNewLine
11Die Fibonacci-Zahlen-Folge ist eine Reihe von Zahlen:
22
3-`0, 1, 1, 2, 3, 5, 8, 13, 21, ...`
3+```text
4+0, 1, 1, 2, 3, 5, 8, 13, 21, ...
5+```
46
57Die 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.
68
79## rekursive Art
810
911``` pascal
1012
1113function FibonacciNumber( n : integer ): integer;
1214begin
1315 if n > 1 then
1416 result := ( FibonacciNumber( n - 1 ) + FibonacciNumber( n - 2 ) )
1517 else if n = 0 then
1618 result := 0
1719 else
1820 result := 1;
1921end;
2022```
2123
2224## iterative Art
2325
2426Diese ist vorzuziehen.
2527
2628``` pascal
2729function Fibonacci(n: Integer): Integer;
2830var
2931 i, u, v, w: Integer;
3032Begin
3133 if n <= 0 then
3234 Result := 0
3335 else if n = 1 then
3436 Result := 1
3537 else
3638 begin
3739 u := 0;
3840 v := 1;
3941 for i := 2 to n do
4042 begin
4143 w := u + v;
4244 u := v;
4345 v := w;
4446 end;
4547 Result := v;
4648 end;
4749End;
4850```
4951
5052## Siehe auch ...
5153
5254- [Some assembly routine which uses the C calling convention that calculates the nth Fibonacci number](http://www.freepascal.org/docs-html/prog/progsu151.html)
5355- [[Solution 3|Tao Yue Solution to Fibonacci Sequence Problem]]
5456- [Wikipedia: Fibonacci-Folge](https://de.wikipedia.org/wiki/Fibonacci-Folge)
5557
5658---
5759*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).*

Back to history