/*
2,青蛙跳台阶问题
(1)一只青蛙一次可以跳上 1 级台阶,也可以跳上2 级。求该青蛙跳上一个n 级的台阶总共有多少种跳法。
(2)一只青蛙一次可以跳上1级台阶,也可以跳上2 级……它也可以跳上n 级,此时该青蛙跳上一个n级的台阶总共有多少种跳法?
*/
#include <stdio.h>
/*
int hoop(int n)
{
if(n<0)
return 0;
else if(n==0)
return 1;
else
return hoop(n-2)+hoop(n-1);
}
*/
int hoop(int n)
{
int m,i;
m=0;
if(n<0)
m=0;
else if(n==0)
m=1;
else
for(i=n-1;i>=0;i--)
m+=hoop(i);
return m;
}
void main(void)
{
int result;
result=hoop(4);
printf("the result is %d\n",result);
}
转载于:https://blog.51cto.com/3414033/736880