int countCattles(int cattles, int years){
return years<=0?cattles: countCattles(cattles*2,years-4);
}
===
就可以了
printf("20年后有%d只\n ", countCattles(1,20);
NB( int NumOfNiu , int year)
{
if( year /4> 0 )
{
NumOfNiu = NumOfNiu *2;
return NB( NumOfNiu , year - 4 );
}
else
retrun NumOfNiu ;
}
#include
main()
{
int t(int n);
int y,n=20;
y=t(n);
printf("%d\n",y);
return 0;
}
int t(int n)
{
int m;
if(n==1)
m=2;
else
m=t(n-1)+1;
return m;
}