C#之打印空心三角形

来源:互联网 发布:连接线共享网络给手机 编辑:程序博客网 时间:2024/05/08 22:19
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace kongxin△
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, j, n;
             
            n =int.Parse( Console.ReadLine());
            
            for (i = 1; i <= n; i++)
            {
                if (i < n)
                    for (j = 1; j < 2 * n; j++)
                    {
                        if (j == n + 1 - i || j == n + i - 1)
                            Console.Write("*");
                        else
                            Console.Write(" ");
                    }

                else
                {
                    for (j = 1; j < 2 * n; j++)
                    {
                        Console.Write("*");
                    }
                }
                Console.Write("\n");
            }
            

            Console.Read();
        }
    }
}
0 0
原创粉丝点击