求问各位大神,怎样用C#编写杨辉三角的程序,除数组以外的方法。
Console.WriteLine("请输出杨辉三角的行数");
string str = Console.ReadLine();
int n = Convert.ToInt32(str);
for (int i = 1; i <= n; i++)
{
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);
}
}