#include
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) = %dn", t, fib(t));
PrintFN(m, n);
return 0;
}
int fib(int n) {
int fib = 1;
int fib_bef = 0;
int fib_buf = 0;
int i = 1;
while (i < n)
{
fib_buf = fib_bef;
fib_bef = fib;
fib = fib_buf + fib_bef;
i++;
}
return fib;
}
void PrintFN(int m, int n) {
int i = 0;
int num =0;//Fibonacci数个数
while (fib(i)
if (fib(i) > m) {
printf("%d ", fib(i));
num++;
}
i++;
}
if (num==0)
{
printf("No Fibonacci number ");
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)