#include
#include
long fib(int n)
{
long f1 = 1;
long f2 = 1;
long fn = 1;
for (int i = 2; i < n; i++)
{
fn = f1 + f2;
f1 = f2;
f2 = fn;
}
return fn;
}
long fib_f(int n)
{
if (1 == n || 2 == n)
return 1;
return fib_f(n - 1) + fib_f(n - 2);
}
int main()
{
int n;
printf("请输入月份:");
scanf("%d", &n);
time_t begin = time(0);
long sum = fib(n);
time_t stop = time(0);
printf("费氏数列第%d月兔子数为%ld,递推方法用时%lf秒\n", n, sum, difftime(stop, begin));
begin = time(0);
sum = fib_f(n);
stop = time(0);
printf("费氏数列第%d月兔子数为%ld,递推方法用时%lf秒\n", n, sum, difftime(stop, begin));
return 0;
}