{ Einfache Rekursionen                    }
{ Autor: Dipl.-Ing. Thomas Speiser        }
{ Source from: http://Codes.TurboTools.de }

{ Fakulaet }
function fak(n: integer): integer;
begin
if n = 1 then
 fak:=1;
else
 fak:=n*fak(n-1);
end;

{ Fibonacci Zahlen }
function fib(n: integer): integer;
begin
 if n < = 2 then
  fib:=1
 else
  fib:=fib(n-1) + fib(n-2);
end;

{ Binomial Koeffizienten }
function binom(n,k: integer): integer;
begin
 if k > 0 then
  binom:=binom(n,k-1) * (n-k+1) / k
 else
  binom:=1;
end;

{ Binaere Suche }
function BinarySearch(a: feld; l,r,k : integer): integer;
var m: integer;
begin
if l > r then BinarySearch := 0
 else
 begin
    m := (l+r) div 2;
  if k < a[m] then BinarySearch := BinarySearch(a,l,m-1,k)
  else
  if k > a[m] then BinarySearch := BinarySearch(a,m+1,r,k)
  else
  BinarySearch:=m;
 end;
end;