欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

控制台输出三角形和菱形图案

程序员文章站 2022-06-11 20:43:38
...

控制台输出三角形和菱形图案

 int numb = int.Parse(Console.ReadLine());

            for (int i = 0; i < numb; i++)
            {
                for (int j = 0; j < numb-1-i; j++)
                {
                    Console.Write(" ");
                }

                for (int x = 0; x < i+1; x++)
                {
                    Console.Write("*");
                    Console.Write(" ");
                }

                Console.WriteLine();
            }

            for (int i = 0; i < numb; i++)
            {
                for (int j = 0; j < numb - 1 - i; j++)
                {
                    Console.Write(" ");
                }

                for (int x = 0; x < 2*i + 1; x++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }

            for (int i = numb-1; i >= 0; i--)
            {
                for (int j = 0; j <= numb-i-1; j++)
                {
                    Console.Write(" ");
                }

                for (int x = 0; x < 2 * i - 1; x++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }