编程论坛
注册
登录
编程论坛
→
C++教室
急!!大侠帮帮忙
进修ing
发布于 2008-11-12 18:50, 626 次点击
用递归函数,一只母兔4岁后每年生一只小母兔,N年后有多少只?
帮帮忙,
谢谢了,
1 回复
#2
lockhawk
2008-11-12 19:19
初学~献丑了
#include <iostream.h>
int tuzi(int x);
int main()
{
int N;
cout<<"please putin N=";
cin>>N;
cout<<"after "<<N<<" years:"<<tuzi(N)<<endl;
return 0;
}
int tuzi(int x)
{
if(x==0||x==1||x==2||x==3)
return 1;
return(tuzi(x-1)+tuzi(x-4));
}
//f(n)=f(n-1)+f(n-4)
1