#include<stdio.h>
#include<time.h>
long Fib_rec(int n)
{
if(n==0||n==1)return(1);
else return(Fib_rec(n-1)+Fib_rec(n-2));
}
long Fib_ite(int n)
{
long fib1,fib2,fib;
int i;
fib=1;
fib=1;
for(i=3;i<=n;i++)
{fib=fib1+fib2;
fib1=fib2;
fib2=fib;
}
return fib;
}
void main()
{
clock_t us1,us2;
int n;
printf("请输入n:\n");
scanf("%d",&n);
us1=clock();
printf("递归函数计算结果:%ld\n",Fib_rec(n));
us2=clock();
printf("递归函数执行时间%ld毫秒\n",us2-us1);
us1=clock();
printf("非递归函数计算结果:%ld\n",Fib_ite(n));
us2=clock();
printf("非递归函数执行时间%ld毫秒\n",us2-us1);
}