C#三角计划问题

时间:2011-06-24 19:06:15

标签: c#

我正在为我的CIS大学课程解决问题。我们只使用for循环和Console.Write(“”)绘制四个三角形星号;和Console.WriteLine();

这是图片的链接

Triangles

我需要一个额外的空间。

    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

我的问题的任何提示或解决方案?

1 个答案:

答案 0 :(得分:0)

我知道这很简单!

我刚刚将三角形c中的空格= 10更改为11,并将row = 1与其余所有一样。

感谢您的帮助提示=)

相关问题