码迷,mamicode.com
首页 > 其他好文 > 详细

15-07-03 for ()语句-打印三角形

时间:2015-07-05 23:44:47      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

1.

            Console.Write("请输入要打印几行:");
            int a = Convert.ToInt32(Console.ReadLine());

            for (int i = 1; i <= a; i++)
            {
                for (int j = 1; j <= i; j++)
                {
                    Console.Write("");
                }
                Console.WriteLine();
            }

技术分享

 

2.

            Console.Write("请输入要打印几行:");
            int a = Convert.ToInt32(Console.ReadLine());

            for (int i = 1; i <= a; i++)
            {
                for (int j = a - i; j >= 0; j--)
                {
                    Console.Write("");
                }

                Console.WriteLine();
            }

技术分享

 

3.

            Console.Write("请输入要打印几行:");
            int a = Convert.ToInt32(Console.ReadLine());

            for (int i = 0; i < a; i++)
            {
                for (int j = 1; j <= a - (i + 1); j++)
                {
                    Console.Write("  ");
                }
                for (int k = 1; k <= i + 1; k++)
                {
                    Console.Write("");
                }
                Console.WriteLine();
            }

技术分享

 

4.

            Console.Write("请输入要打印几行:");
            int a = Convert.ToInt32(Console.ReadLine());

            for (int i = 1; i <= a; i++)
            {
                for (int j = 0; j <= i - 2; j++)
                {
                    Console.Write("  ");
                }
                for (int k = 0; k <= a - i; k++)
                {
                    Console.Write("");
                }
                Console.WriteLine();
            }

技术分享

15-07-03 for ()语句-打印三角形

标签:

原文地址:http://www.cnblogs.com/jia520110270/p/4623181.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!