C#/Foundation

013.9번 문제의 5층 피라미드 그리는 프로그램을 이용하여 n 층의 피라미드를 그리는 함수를 작성하여 3, 5, 7층의 피라미드를 그리시오

페프 2021. 4. 14. 01:24
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B013
{
    class Program
    {
        static void Main(string[] args)
        {
            DrawPyramid(3);
            DrawPyramid(5);
            DrawPyramid(7);
        }

        private static void DrawPyramid(int n)
        {
            for(int i = 1; i <= n; i++)
            {
                for(int j=1;j<=n-i;j++)
                    Console.Write(" ");
                for (int k = 1; k <= 2 * i - 1; k++)
                    Console.Write("*");
                Console.WriteLine();
            }
        }
    }
}