int i, iCount=1;
unsigned long fn[100] = {1, 1};
while (fn[iCount++] < 2147483648)
fn[iCount] = fn[iCount-1] + fn[iCount-2];
for (i=0; i<iCount; i++)
printf("%lu ", fn[iCount-i-1]);
遞迴 (recursive) 方式
正的印
void printRecursiveForwardFibonacci(unsigned long fn1, unsigned long fn2)
{
if (fn1 > 2147483647) return;
printf("%lu ", fn1);
printfRecursiveForwardFibonacci(fn1 + fn2, fn1);
}
printRecursiveForwardFibonacci(1, 0);
倒過來印
void printRecursiveBackwardFibonacci(unsigned long fn1, unsigned long fn2)
{
if (fn1 > 2147483647) return;
printfRecursiveBackwardFibonacci(fn1 + fn2, fn1);
printf("%lu ", fn1);
}
printRecursiveBackwardFibonacci(1, 0);