非递归法
unsigned long long Fibonacci(unsigned long long n)
{
int n1, n2, temp, i;
if (n > 2)
for (n1 = 1, n2 = 1, i = 3; i <= n; i++)
{
temp = n1 + n2;
n1 = n2;
n2 = temp;
}
else n2 = 1;
return n2;
}
递归法
unsigned long long Fibonacci(unsigned long long n)
{
if(n > 2)
return Fibonacci(n - 1) + Fibonacci(n - 2);
else
return 1;
}