Making pyramid using c#

后端 未结 13 2074
花落未央
花落未央 2021-01-03 11:04

My question is how to make a pyramid using * and \'space\' in C#? The output will be like this.

     *
    * *
   * * *
  * * * *
 * * * * *
<
13条回答
  •  鱼传尺愫
    2021-01-03 11:18

    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace Star_Pyramid
    {
        class Program
        {
            static void Main(string[] args)
            {
                Program o = new Program();
                o.show();
    
                Console.ReadKey();
            }
            void show()
            {
               for (int i = 1; i <= 12; i++)
                {
                    for (int j = 1; j <= 9 - i / 2; j++)
                    {
                        Console.Write("   ");
                    }
                    for (int k = 1; k <= i; k++)
                    {
                        Console.Write(" * ");
                        Console.Write(" ");
    
    
                    }
                    Console.WriteLine();
    
                }
            }
        }
    }
    

提交回复
热议问题