/*
** Compute the value of the n'th Fibonacci number, recursively. 递归法
*/
long fibonacci( int n )
{
if( n <= 2 )
return 1;
return fibonacci( n - 1 ) + fibonacci( n - 2 );
}
/*
** Compute the value of the n'th Fibonacci number, iteratively.迭代法
*/
long fibonacci( int n )
{
long result;
long previous_result;
long next_older_result;
result = previous_result = 1;
while( n > 2 ){
n -= 1;
next_older_result = previous_result;
previous_result = result;
result = previous_result + next_older_result;
}
return result;
}