卡特兰数的芹桐颂求解:
h(n)=h(n-1)*(4*n-2)/(n+1);
用递归实现最容易轮袭:
#include
/* h(n)=h(n-1)*(4*n-2)/(n+1); */
int fun(int n)
{
int ii = 0;
if (1 >= n)
{
return 1;
}
else
{
ii = (4 * n - 2) / (n + 1);
return (ii * fun(n - 1));
}
}
int main()
{
int n = 0;
printf("Input the index:\n"嫌郑);
scanf("%d", &n);
printf("the result is: %d. \n", fun(n));
return 0;
}