//Função Normal Clássica Function Fibonacci (const N: Integer): Int64; var I: Integer; f1, f2: Int64; Begin if N <= 1 then Result := N else begin f1 := 0; f2 := 1; for N := 1 to N do begin Result := f1 + f2; f2 := f1; f1 := Result; end; end; End; //Função Recursiva Clássica Function Fibonacci(const N: Integer): Int64; Var Res: Int64; Begin If N <= 2 then Res := 1 else Res := Fibonacci(N-2) + Fibonacci(N-1); Result := Res; end; //Função normal com Index e Qtd Function Fib(Const Index, Qtd: Integer): Int64; Var I: Integer; f1, f2: Int64; Begin If Index > 0 then begin f1 := 0; f2 := 1; for I := 1 to (Index + Qtd) do begin Result := f1 + f2; f2 := f1; f1 := Result; end; end else begin If Index < 0 then begin f1 := 0; f2 := -1; for I := -1 downto (Index - Qtd) do begin Result := f1 - f2; f2 := f1; f1 := Result; end; end else begin Showmessage("Com índice zero não é possível saber a direção (positivo ou negativo)."); end; end; End;