http://pta.patest.cn/pta/test/13/exam/3/question/477
#include <stdio.h>
int fib( int n );
void PrintFN( int m, int n );
int main()
{
int m, n, t;
scanf("%d %d %d", &m, &n, &t);
printf("fib(%d) = %d\n", t, fib(t));
PrintFN(m, n);
return 0;
}
int fib( int n )
{
if(n==1||n==2)
{
return 1;
}
if(n>2)
{
return fib(n-1)+fib(n-2);
}
}
void PrintFN( int m, int n )
{
int i=0,j,k=1,count=0;
for(j=0;j<=21;j++)
{
i++;
if(fib(i)>=m&&fib(i)<=n)
{
count++;
printf("%d ",fib(i));
}
}
if(count==0)
{
printf("No Fibonacci number");
}
}
本文介绍了一个使用C语言实现的斐波那契数列程序,该程序包括递归计算斐波那契数列的功能及打印指定范围内所有斐波那契数的功能。通过对递归函数的理解和应用,展示如何解决实际编程问题。
580





