/* 斐波那契数列(Fibonacci) */
/* Win2K3 + VC6下通过 */
#include “stdio.h”
#include “stdlib.h”
#include “conio.h”
int fib( int n )
{
if ( n == 0 ) {
return 0;
}
if ( n == 1 ) {
return 1;
}
if ( n > 1 ) {
return ( fib( n – 2 ) + fib ( n – 1 ) );
}
return 0;
}
void main()
{
int i;
printf ( “Enter i(i>=0&&i<=35): ” );
while ( 1 ) {
scanf( “%d”, &i );
if ( (i >= 0) && (i <= 35) ) {
break;
}
printf(“\n不合理,重新输入!\n”);
}
printf ( “fib(%d) = %d\r\n”, i, fib(i) );
system(“pause”);
}
>> 本文固定链接: http://www.vcgood.com/archives/107