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

五角星循环重难点!!!

时间:2015-04-02 20:37:14      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:

static void Main(string[] args)
        {
            while (true)
            {
               
           
            /*★
              ★★                                                    //最重要的就是找规律 i--行
              ★★★                                                                              j--列
              ★★★★
              ★★★★★
             */
           
            /*string s = "★";
            int n;
            Console.WriteLine("请输入一个数:");
            n = Convert.ToInt32(Console.ReadLine());
            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <=i; j++)
                {
                    Console.Write(s);
                }
                Console.WriteLine();
            }
                */

 


                /*★★★★★
                  ★★★★
                  ★★★
                  ★★
                  ★
                 */
               
                /* string s = "★";
                int n;
                Console.WriteLine("请输入一个数:");
                n = Convert.ToInt32(Console.ReadLine());
                for (int i = 1; i <= n; i++)
                {
                    for (int j = 1; j <=n+1-i; j++)
                    {
                        Console.Write(s);
                    }
                    Console.WriteLine();
                }
              
                */

                /*
                        ★
                      ★★
                    ★★★
                  ★★★★
                ★★★★★
                */

                /*
                  string s = "★";
                int n;
                Console.WriteLine("请输入一个数:");
                n = Convert.ToInt32(Console.ReadLine());
                for (int i = 1; i<=n; i++)
                {
                    for (int j = 1; j <=(n-i); j++)
                    {
                        Console.Write("  ");
                    }
                    for (int t = 1; t <=i ; t++)
                    {
                         Console.Write(s);
                    }
                    Console.WriteLine("");
                }
                */

                /*
                         ★
                       ★★★
                     ★★★★★
                   ★★★★★★★
                 ★★★★★★★★★
                */
               /*
                string s = "★";
                int n;
                Console.WriteLine("请输入一个数:");
                n = Convert.ToInt32(Console.ReadLine());
                for (int i = 1; i <=n; i++)
                {
                    for (int j = 1; j <=(n-i); j++)
                    {
                        Console.Write("  ");
                    }
                    for (int t = 1; t<=(2*i-1);t++)
                    {
                        Console.Write(s);
                    }
                    Console.WriteLine();
                }
                */


                /*
                    ★
                   ★★
                  ★★★
                 ★★★★
                ★★★★★ 
                 ★★★★
                  ★★★
                   ★★
                    ★
                */
               /* string s = "★";
                int n;
                Console.WriteLine("请输入一个数:");
                n = Convert.ToInt32(Console.ReadLine());
                for (int i = 1; i <=n; i++)
                {
                        for (int b = 1; b <=n-i; b++)
                      {
                        Console.Write(" ");
                      }
                    for (int j= 1; j <=i; j++)
                      {
                         Console.Write(s);
                         ;
                      }
                    Console.WriteLine();
                }

 

                    for (int p = 1; p <=n; p++)
                    {
                        for (int o = 1; o <=p; o++)
                        {
                            Console.Write(" ");
                        }
                        for (int k = 1; k <=n-p; k++)
                        {
                             Console.Write(s);
                        }
                        Console.WriteLine();
                    }
                       
                    Console.WriteLine();
                  

                /*
                 ★
               ★★★
             ★★★★★
               ★★★
                 ★
                 */
               string s = "★";
                int n;
                Console.WriteLine("请输入一个数:");
                n = Convert.ToInt32(Console.ReadLine());

                for (int i = 1; i <=n; i++)
                {
                    for (int x = 1; x <=n-i; x++)
                    {
                        Console.Write("  ");
                    }
                    for (int y = 1; y <=2*i-1; y++)
                    {
                        Console.Write(s);
                    }  
                   
                    Console.WriteLine();
                }
                for (int t = 1; t <n; t++)
                {
                    for (int z = 1; z <=t; z++)
                    {
                        Console.Write("  ");
                    }
                    for (int q = 1; q <=2*(n-t)-1; q++)//最重要的公式!!
                    {
                         Console.Write(s);
                    }
                    Console.WriteLine();
                }
               
                /*
                 ★★
                ★★★
               ★★★★
              ★★★★★
                */

                 /*string s = "★";
                int n;
                Console.WriteLine("请输入一个数(大于4):");
                n = Convert.ToInt32(Console.ReadLine());
                for (int i = 4; i <= n; i++)
                {
                    for (int j = 1; j <= (n - i); j++)
                    {
                        Console.Write("  ");
                    }
                    for (int t = 1; t <= (2 * i-1); t++)
                    {
                        Console.Write(s);
                    }
                    Console.WriteLine();
                }
                    */

                /*  ★★★★★★
                  ★★★★★★★
                ★★★★★★★★
                ★★★★★★★★
                ★★★★★★★★
                ★★★★★★★★
                ★★★★★★★
                ★★★★★★
                 */
                /*string s = "★";
                 int n;
                 Console.WriteLine("请输入一个数:");
                 n = Convert.ToInt32(Console.ReadLine());
                 for (int i = 1; i <=n; i++)
                 {
                     for (int j = 1; j <= n; j++)
                     {
                         if (i == 1 && j == 1||i==1&&j==2||i==2&&j==1||i==(n-1)&&j==n||i==n&&j==(n-1)||i==n&&j==n)
                         {
                             Console.Write("  ");
                         }

                         else
                         {
                             Console.Write(s);
                         }
                     }
                     Console.WriteLine();
                 }*/

                

五角星循环重难点!!!

标签:

原文地址:http://www.cnblogs.com/lk-kk/p/4387975.html

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