static void Main(string[] args)
{
Console.WriteLine("请输出杨辉三角的行数");
string str = Console.ReadLine();
int n = Convert.ToInt32(str);
for (int i = 1; i <= n; i++)
{
for (int k = 1; k <= n + 1 - i; k++)
{
Console.Write(" ");
}
for (int j = 1; j <= i; j++)
{
Console.Write(getValue(i, j) + " ");
}
Console.WriteLine();
}
}
public static int getValue(int i,int j) {
if (j==1||i==j)
{
return 1;
}
else
{
return getValue(i - 1, j - 1) + getValue(i - 1, j);
}
}
{
Console.WriteLine("请输出杨辉三角的行数");
string str = Console.ReadLine();
int n = Convert.ToInt32(str);
for (int i = 1; i <= n; i++)
{
for (int k = 1; k <= n + 1 - i; k++)
{
Console.Write(" ");
}
for (int j = 1; j <= i; j++)
{
Console.Write(getValue(i, j) + " ");
}
Console.WriteLine();
}
}
public static int getValue(int i,int j) {
if (j==1||i==j)
{
return 1;
}
else
{
return getValue(i - 1, j - 1) + getValue(i - 1, j);
}
}