用递归实现Fibonacci数列
#include "stdafx.h"
#define N 20
int Fibonacci( int n )
{
if ( n == 1 || n == 2 )
return(1);
else
return(Fibonacci( n - 1 ) + Fibonacci( n - 2 ) );
}
void main()
{
int i = 0;
for ( i = 1; i <= N; i++ )
{
printf( "%5d", Fibonacci( i ) );
if ( i % 5 == 0 )
printf( "\n" );
}
printf( "\n" );
printf( "Hello World!\n" );
}
以上就是Fibonacci数列的代码,实现环境是VC 6.0
人生有几个十年呢?点点滴滴,用文字记录