//用递归Finbonacci数列
/*#include
long fun(int );
int main(void)
{
int x;
printf("请输入x的的值:");
scanf("%d",&x);
printf("第%d的值为:%ld\n",x,fun(x));
}
long fun(int x)
{
long sum;
if(x==1||x==2)
sum=1;
else
sum=fun(x-1)+fun(x-2);
return sum;
}*/
//bu用递归Finbonacci数列
/*#include
long fun(int );
int main(void)
{
int x;
scanf("%d",&x);
printf("%ld\n",fun(x));
return 0;
}
long fun(int x )
{
long a=1,b=1,c;
int i;
if(x==1||x==2)
c=1;
else
if(x>2)
{
for(i=3;i<=x;i++)
{
c=a+b;
a=b;
b=c;
}
}
return c;
}*/
//用递归求阶乘;
/*#include
long fun(int );
int main(void)
{
int s;
scanf("%d",&s);
printf("%ld\n",fun(s));
return 0;
}
long fun(int x)
{
long sum=1;
if(x==1||x==0)
sum=1;
else
sum=x*fun(x-1);
return sum;
}*/
/*#include
void move(char ,char );
void honio(int ,char ,char ,char );
int main(void)
{
int n;
printf("请输入要移动的盘子的个数:");
scanf("%d",&n);
honio(n,'X','Y','Z');
return 0;
}
void move(char x,char y)
{
printf("%c->%c\n",x,y);
}
void honio(int n,char X,char Y,char Z)
{
if(n==1)
move(X,Z);
else
{
honio(n-1, X, Z,Y);
move(X,Z);
honio(n-1, Y, X,Z);
}
}*/
//不用递归大于x值得Finboacci的值
/*(#include
long fun(int);
int main(void)
{
int x;
printf("请输入一个大于x值得Finboacci的值:");
scanf("%d",&x);
printf("大于%d的finboacci的值为%d\n",x,fun(x));
return 0;
}
long fun(int x)
{
long sum=0;
int i,a=1,b=1;
for(i=1;i<=x;i++)
{
if(sum<=x)
{
sum=a+b;
a=b;
b=sum;
}
else break;
}
return sum;
}*/
//用递归大于x值得Finboacci的值
#include
long fun(int );
int main(void)
{
int x;
printf("请输入一个大于x值得Finboacci的值:");
scanf("%d",&x);
printf("大于%d的finboacci的值为%d\n",x,fun(x));
return 0;
}
long fun(int x )
{
int i;
long a=1;
for(i=1;a<=x;i++)
if(i==1||i==2)
a=1;
else
a=fun(i-1)+fun(i-2);
return a;
}