斐波那契数列

前提条件

  1. 熟悉if-else语句
  2. 熟悉while循环
  3. 熟悉C运算符

斐波那契系列:序列中的第n个数字=第(n-1)个数字+(n-2)个数字。例如:0,1,1,2,3,5,8,13,21,34,55,89………

代码

#include <stdio.h>
int main()
{
    long int numcount,nextnumcount;
    long int numcount1 = 0, numcount2 = 1;

    printf("输入斐波那契数列的最后一个数字: ");
    scanf("%ld", &numcount);

    printf("Fibonacci Series: \n");

    while(numcount1<numcount)
    {
        printf("%ld, ", numcount1);
        nextnumcount = numcount1 + numcount2;
        numcount1 = numcount2;
        numcount2 = nextnumcount;
    }
    return 0;
}