实例实现斐波那契数列;
源码:
#include <stdio.h>
int fib(int n);
int main()
{
int n = 1;
while(n <= 10)
{
printf("%d ",fib(n));
n++;
}
return 0;
}
int fib(int n)
{
if(n == 1 || n == 2)
{
return 1;
}
return fib(n-1)+fib(n-2);
}
实例实现斐波那契数列;
源码:
#include <stdio.h>
int fib(int n);
int main()
{
int n = 1;
while(n <= 10)
{
printf("%d ",fib(n));
n++;
}
return 0;
}
int fib(int n)
{
if(n == 1 || n == 2)
{
return 1;
}
return fib(n-1)+fib(n-2);
}