Making pyramid using c#

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

    using System;               
    using System.Collections.Generic;               
    using System.Linq;
    
    using System.Text;
    
    namespace pyramid_star
    
    {
    
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("enter a number:");
                int n = Convert.ToInt32(Console.ReadLine());
                for (int i = 1; i <= n; i++)
                {
                    for (int x = i; x <= n; x++)
                    {
                        Console.Write(" ");
                    }
                    for (int j = 1; j <= i; j++)
                    {
                        Console.Write("*"+" ");
                    }
                    Console.WriteLine();
                }
                Console.ReadLine();
            }
        }
    }
    

提交回复
热议问题