C#三角形规划问题
我正在为我的CIS大学班解决一个问题。我们将绘制四个三角形星号,仅用于循环和控制台;和Console.WriteLine() 这里有一个图片链接 还有一个空间比我需要的多C#三角形规划问题,c#,C#,我正在为我的CIS大学班解决一个问题。我们将绘制四个三角形星号,仅用于循环和控制台;和Console.WriteLine() 这里有一个图片链接 还有一个空间比我需要的多 class Diamond { static void Main(string[] args) { int row; // the current row int stars; // the number of stars
class Diamond
{
static void Main(string[] args)
{
int row; // the current row
int stars; // the number of stars
int spaces; // the number of spaces
// top half (1st five lines)
for ( row = 1; row <= 11; row++ )
{
for ( spaces = 1; spaces > row; spaces-- )
Console.Write( " " );
for ( stars = 1; stars <= row - 1; stars++ )
Console.Write( "*" );
Console.WriteLine();
} // end outer for
//Triangle B
for (row = 0; row <= 11; row++)
{
Console.WriteLine();
for (spaces = 10; spaces > row; spaces--)
Console.Write("*");
for (stars = 1; stars <= row - 1; stars++)
Console.Write("");
} // end outer for
//Triangle C
for (row = 0; row <= 11; row++)
{
for (stars = 0; stars <= row - 1; stars++)
Console.Write(" ");
for (spaces = 10; spaces > row; spaces--)
Console.Write("*");
Console.WriteLine();
} // end outer for
//Triangle D
for (row = 1; row <= 10; row++)
{
for (spaces = 10; spaces > row; spaces--)
Console.Write(" ");
for (stars = 0; stars <= row - 1; stars++)
Console.Write("*");
Console.WriteLine();
} // end outer for
Console.ReadLine();
} // end Main
} // end class Diamond
钻石级
{
静态void Main(字符串[]参数)
{
int row;//当前行
int stars;//星数
int spaces;//空格数
//上半部分(前五行)
对于(行=1;行;空格--)
控制台。写(“”);
因为(stars=1;stars我知道这很简单
我只是将三角形c中的空格=10改为11,并将行=1和其他所有行一样
感谢您的帮助提示=)您是否尝试过使用索引?