从 0 开始,如: 0,1,1,2,3,5,8…
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
//递归实现
int Fib(int x)
{
if (x <= 0)
{
return 0;
}
else if (x>2)
{
return Fib(x-1) + Fib(x-2);
}
else if(x <=2 && x > 0)
{
return 1;
}
}
int main()
{
int n = 0;
scanf("%d", &n);
n = n -1;
printf("%d", Fib(n));
return 0;
}
从 1 开始,如: 1,1,2,3,5,8…
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
//递归实现
int Fib(int n)
{
if (n >= 3)
return Fib(n - 2) + Fib(n - 1);
else
return 1;
}
int main()
{
int n = 0;
scanf("%d", &n);
n = n -1;
printf("%d", Fib(n));
return 0;
}
标签:return,数列,int,波拉,else,Fib,main,SECURE
From: https://blog.csdn.net/ydm_ymz/article/details/143061894