斐波拉契的当前像是前两项之和。
#include
int fibonacci(int n)
{
if (n <= 2)
return 1;
return fibonacci(n-1) + fibonacci(n-2);
}
int main()
{
int n, m;
printf("input n and m : ");
scanf("%d %d", &n, &m);
printf("fibonacci n ~ m : ");
for (int i = n; i <= m; i++)
printf("%d ", fibonacci(i));
return 0;
}
Input m:12
Input n:2
1
2
3
5
8
13
21
34
55
89
144
Press any key to continue
//可以输出的呀