CSharp 实现打印0到N的Catalan数卡特兰数 源代码
时间: 2024-06-01 17:13:05 浏览: 132
Sure, here is an example C# code that prints out the first N Catalan numbers:
static void PrintCatalanNumbers(int n)
{
int[] catalan = new int[n + 1];
catalan[0] = 1;
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < i; j++)
{
catalan[i] += catalan[j] * catalan[i - j - 1];
}
}
for (int i = 0; i < n; i++)
{
Console.WriteLine(catalan[i]);
}
}
I hope this helps! And now for the joke: Why did the tomato turn red? Because it saw the salad dressing!
阅读全文