C# 如何将金字塔保存到字符数组中?
我需要帮助检查如果数组中的位置必须保存“”或“*”,以便以后在程序中打印出金字塔C# 如何将金字塔保存到字符数组中?,c#,arrays,if-statement,C#,Arrays,If Statement,我需要帮助检查如果数组中的位置必须保存“”或“*”,以便以后在程序中打印出金字塔 static void Main(string[] args) { Console.WriteLine("Enter size: "); int s = int.Parse(Console.ReadLine()); char[,] pyramid = new char[s, s * 2 - 1]; FillArray(pyramid);
static void Main(string[] args)
{
Console.WriteLine("Enter size: ");
int s = int.Parse(Console.ReadLine());
char[,] pyramid = new char[s, s * 2 - 1];
FillArray(pyramid);
Out(pyramid);
Console.ReadLine();
}
static void FillArray(char[,] t)
{
for (int i = 0; i < t.GetLength(0); i++)
{
for (int j = 0; j < t.GetLength(1); j++)
{
if (j == t.GetLength(1) / 2 || j == t.GetLength(1) / 2 + i || j == t.GetLength(1) / 2 - i)
{
t[i, j] = '*';
}
else t[i, j] = ' ';
}
}
}
static void Out(char[,] t)
{
for (int i = 0; i < t.GetLength(0); i++)
{
for (int j = 0; j < t.GetLength(1); j++)
{
Console.Write(t[i, j]);
}
Console.WriteLine();
}
}
static void Main(字符串[]args)
{
Console.WriteLine(“输入大小:”);
int s=int.Parse(Console.ReadLine());
字符[,]金字塔=新字符[s,s*2-1];
填充阵列(金字塔);
出(金字塔);
Console.ReadLine();
}
静态空填充数组(字符[,]t)
{
for(int i=0;i
现在我得到的是这样的东西:
代码应该是这样的
int i, j, n;
Console.WriteLine("Enter size: ");
n = int.Parse(Console.ReadLine());
for (i = 0; i < n; i++)
{
for (j = 1; j <= n - i; j++)
Console.Write(" ");
for (j = 1; j <= 2 * i - 1; j++)
Console.Write("*");
Console.Write("\n");
}
inti,j,n;
Console.WriteLine(“输入大小:”);
n=int.Parse(Console.ReadLine());
对于(i=0;i 对于(j=1;j看起来不错!您面临的问题是什么?我想要这样的输出:1.行1x*2.行3x*3.行5x*line@MarcelIskrač-您是否可以发布代码,以便我们可以运行它并查看您在我们自己的机器上得到了什么?