码迷,mamicode.com
首页 > 其他好文 > 详细

打印出五种图案

时间:2015-04-13 20:36:50      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

 while (true)                                                                                   //迭代    要找出规律   看图形各行与各行 (‘‘ "),( "☆")之间的规律
            {
             Console.Write("请选择您想要得到的图形?A正方形;B三角形;C平行四边形;D菱形;E梯形:");
            string n = Console.ReadLine();
            Console.Write("请输入数字:");
            int m = Convert.ToInt32(Console.ReadLine());
            switch (n)
            {
                case "A":
                    for (int i = 1; i <= m; i++)
                    {
                        Console.Write("☆");
                   
                        for (int j = 1; j <= m; j++)
                        {
                            Console.Write("☆");
                        }
                        Console.Write("\n");
                    }
                    break;
                case "B":
                    for (int i = 1; i <= m; i++)
                    {
                        for (int j = 1; j <= m - i; j++)
                        {
                            Console.Write("  ");
                        }
                        for (int k = 1; k <= 2 * i - 1; k++)
                        {
                            Console.Write("☆");
                        }
                        Console.Write("\n");
                    }
                    break;
                case "C":
                    for (int i = 1; i <= m; i++)
                    {
                        for (int j = 1; j <=m-i; j++)
                        {
                            Console.Write("  ");
                        }
                        for (int k =1; k <= m; k++)
                        {
                            Console.Write("☆");
                        }
                        Console.Write("\n");
                    }  
                    break;
                case "D":
                    for (int i = 1; i <= m; i++)
                    {
                        for (int j = 1; j <= m - i; j++)
                        {
                            Console.Write("  ");
                        }
                        for (int k = 1; k <= 2 * i - 1; k++)
                        {
                            Console.Write("☆");
                        }
                        Console.Write("\n");
                    }
                    for (int p = 1; p <= m; p++)
                    {
                        for (int q = 1; q <= p; q++)
                        {
                            Console.Write("  ");
                        }
                        for (int h = 1; h <= 2 *(m-p) - 1; h++)
                        {
                            Console.Write("★");
                        }
                        Console.Write("\n");
                    }
                    break;
                case "E":
                    for (int i = 1; i <= m; i++)
                    {
                        for (int j = 1; j <= m - i; j++)
                        {
                            Console.Write("  ");
                        }
                        for (int k = 1; k <= 2 * i + 3; k++)
                        {
                            Console.Write("☆");
                        }
                        Console.Write("\n");
                    }
                    break;
                default:
                     Console.Write("您的输入有误!");
                     break;
            }
            Console.ReadLine();
            }

打印出五种图案

标签:

原文地址:http://www.cnblogs.com/Mr-xue/p/4423054.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!