home *** CD-ROM | disk | FTP | other *** search
- {$N+,E+}
- Program Fibonacci;
- { This program will calculate the NumToCalc Fibonacci }
- { number. It is intended as an example of using the call }
- { stack to examine the currently active procedures }
-
- Const
- NumToCalc = 10; { The specific Fib num to calc }
-
- Function Fib(Num : Integer) : Extended;
- { Recursive function to calulate a Fibonacci number. This }
- { function will be used to show how to use the call stack }
- { feature. }
- Var
- Fib1, Fib2 : Extended; { Local vars for calculation }
-
- Begin
- If Num = 0 Then
- Fib := 0.0
- Else
- If Num = 1 Then
- Fib := 1.0
- Else
- Begin
- Fib1 := Fib( Num - 1 );
- Fib2 := Fib( Num - 2 );
- Fib := Fib1 + Fib2;
- End;
- End;
-
- Begin
- Writeln( NumToCalc,' Fibonacci Number is ',
- Fib( NumToCalc ):20:10 );
- End.