--- --- --- --- --- --- ( 循环 ) --- --- --- --- --- ---
void FSum(int n)
{
int a = 0,b = 1,sum,i;
if (n >= 1) { sum = a; printf("%d ",sum); }
if (n >= 2) { sum = b; printf("%d ",sum); }
if (n >= 3)
for(i = 3; i <= n; i++)
{
sum = a + b;
a = b;
b = sum;
printf("%d ",sum);
}
}
void main()
{ FSum(10); }
--- --- --- --- --- --- -- ( 递归 ) --- --- --- --- --- ---
int FSum(int n)
{
if (n < 3) return n<2 ? 0 : 1;
return FSum(n-1) + FSum(n-2);
}
void main()
{
int i;
for(i = 1; i <= 10; i++) printf("%d ",FSum(i));
}