打印实心菱形与空心菱形

//打印实心菱形

            //Console.WriteLine("请输入正整数n");

            //int n = int.Parse(Console.ReadLine());

            //int i = 0, j = 0, k = 0;

            ////先打印上半部分的菱形

            //for (i = 1; i <= n; i++)

            //{

            //    //先使用for循环打印空格

            //    for (j = 1; j <= n - i; j++)

            //    {

            //        Console.Write(" ");

            //    }

            //    //使用for循环打印*

            //    for (k = 1; k <= 2 * i - 1; k++)

            //    {

            //        Console.Write("*");

            //    }

            //    Console.WriteLine();

            //}

            ////打印下半部分菱形

            //for (i = n - 1; i >= 1; i--)

            //{

            //    //打印空格

            //    for (j = 1; j <= n - i; j++)

            //    {

            //        Console.Write(" ");

            //    }

            //    //打印*

            //    for (k = 1; k <= 2 * i - 1; k++)

            //    {

            //        Console.Write("*");

            //    }

            //    Console.WriteLine();

            //}

            //打印空心菱形

            Console.WriteLine("请输入正整数n");

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

            int i = 0, j = 0, k = 0;

            //先打印上半部分的菱形

            for (i = 1; i <= n; i++)

            {

                //先使用for循环打印空格

                for (j = 1; j <= n - i; j++)

                {

                    Console.Write(" ");

                }

                //使用for循环打印*

                for (k = 1; k <= 2 * i - 1; k++)

                {

                    //Console.Write("*");

                    if (k == 1 || k == 2 * i - 1)

                    {

                        Console.Write("*");

                    }

                    else

                    {

                        Console.Write(" ");

                    }

                }

                Console.WriteLine();

            }

          

            //打印下半部分菱形

            for (i = n - 1; i >= 1; i--)

            {

                //打印空格

                for (j = 1; j <= n - i; j++)

                {

                    Console.Write(" ");

                }

                //打印*

                for (k = 1; k <= 2 * i - 1; k++)

                {

                    //Console.Write("*");

                    if (k == 1 || k == 2 * i - 1)

                    {

                        Console.Write("*");

                    }

                    else

                    {

                        Console.Write(" ");

                    }

                }

                Console.WriteLine();

            }

你可能感兴趣的:(打印实心菱形与空心菱形)