斐波那契数列指的是这样一个数列:1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, …
#include <stdio.h>
long long Fbnl(int N) //非递归
{
int a1 = 0;
int a2 = 1;
int a3 = N;
printf(" 0 ");
for (int i = 2; i <N; i++)
{
printf("%2d ", a2);
a3 = a2 + a1;
a1= a2;
a2 = a3;
}
printf("\n");
return a3;
}
// 递归
//long long Fbnl(int N)
//{
// return N < 2 ? N : Fbnl(N - 1) + Fbnl(N - 2);
//}
int main()
{
int tmp = Fbnl(7);
printf("%d\n", tmp);
return 0;
}