Making pyramid using c#

后端 未结 13 2183
花落未央
花落未央 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:33

    class Program
    
    {
    
        static void Main(string[] args)
    
        {
            int num;
            Console.WriteLine("enter level");
            num = Int32.Parse(Console.ReadLine());
            int count = 1;
    
            for (int lines = num; lines >= 1; lines--)
            {
    
                for (int spaces = lines - 1; spaces >= 1; spaces--)
                {
                    Console.Write(" ");
    
                }
                for (int star = 1; star <= count; star++)
                {
                    Console.Write("*");
                    Console.Write(" ");
    
                }
                count++;
    
                Console.WriteLine();
            }
            Console.ReadLine();
        }
    }
    

提交回复
热议问题