Feedback

Fibonacci

Sprache: C#

Gibt das n-te Element der Fibonacci Folge mit der Formel von de Moivre zurück.
public int fibonacci(int n)
{
     double sqrt = Math.Sqrt(5);
     return (int)((1 / sqrt) * ((Math.Pow((1 + sqrt) / 2, n)) - (Math.Pow((1 - sqrt) / 2, n))));
}
public int fibonacci(int n)
{
     double sqrt = Math.Sqrt(5);
     return (int)((1 / sqrt) * ((Math.Pow((1 + sqrt) / 2, n)) - (Math.Pow((1 - sqrt) / 2, n))));
}