c#十行十列直角三角形的杨辉三角
时间: 2024-06-17 16:04:37 浏览: 114
好的,我来为您介绍一下C#中如何输出十行十列直角三角形的杨辉三角。
代码如下:
```
using System;
class Program
{
static void Main(string[] args)
{
int[,] triangle = new int[10, 10];
for (int i = 0; i < 10; i++)
{
triangle[i, 0] = 1;
triangle[i, i] = 1;
}
for (int i = 2; i < 10; i++)
{
for (int j = 1; j < i; j++)
{
triangle[i, j] = triangle[i - 1, j - 1] + triangle[i - 1, j];
}
}
for (int i = 0; i < 10; i++)
{
for (int j = 0; j <= i; j++)
{
Console.Write(triangle[i, j] + " ");
}
Console.WriteLine();
}
}
}
```
输出结果如下:
```
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
```
阅读全文