C# 控制台程序输出倒三角

来源:互联网 发布:淘宝店铺虚拟转实物 编辑:程序博客网 时间:2024/06/09 13:43

            int a = 5;          //总共五行
            for (int i = a; i >=1 ; i--)
            {
                for (int h = 1; h<=a-i ; h++)
                {
                    Console.Write(" ");
                }
                for (int j = 0; j <2*i-1 ; j++)   
                {
                    Console.Write("*");       
                }
                Console.WriteLine("\n");   //换行
            }
            Console.ReadKey();

 

输出结果:

*******

 *****

  ***

   *

 

原创粉丝点击