#include<stdio.h>
int fib(int n)
{
if (n <= 2)
{
return 1;
}
return fib(n - 1) + fib(n - 2);
}
int Fibonacci(int x)
{
int a = 0;
int b = 1;
int c = 0;
if (x == 1)
return 1; //当x=1,返回1
if (x == 0)
return 0; //当x=0,返回0
while (x >= 2) //输入x>=2时,进行迭代
{
c = a + b; //每次迭代令c=a+b,即进行f(x)=f(x-1)+f(x-2)
a = b; //使得a,b往后移一个数字
b = c;
x--;
}
return c;
}
int main()
{
printf("%d\n", fib(4));
printf("%d\n", Fibonacci(4));
return 0;
}