利用for循环的嵌套输出图形--课后作业

for (int i = 1; i <= 8; i++)
            {
                int a, b;
                for (a = 1; a < i; a++)
                    Console.Write(" ");
                for (b = 8; b >= i; --b)
                    Console.Write("*");
                Console.WriteLine();
            }
            Console.ReadLine();

  作业一得到的是这个图形利用for循环的嵌套输出图形--课后作业_第1张图片

for (int i = 1; i <= 8; i++)
            {
                int a, b, c;
                for (a = 8; a > i; a--)
                    Console.Write(" ");
                for (b = 1; b <= i; b++)
                    Console.Write("*");
                for (c = 1; c < i; c++)
                    Console.Write("*");
                Console.WriteLine();
            }
            for (int i = 1; i <= 7; i++)
            {
                int a, b, c;
                for (a = 1; a <= i; a++)
                    Console.Write(" ");
                for (b = 7; b >= i; b--)
                    Console.Write("*");
                for (c = 7; c > i; --c)
                    Console.Write("*");
                Console.WriteLine();
            }
            Console.ReadLine();

  作业二得到的是这个图形利用for循环的嵌套输出图形--课后作业_第2张图片

转载于:https://www.cnblogs.com/whytohow/p/4700498.html

你可能感兴趣的:(利用for循环的嵌套输出图形--课后作业)