首页 > 其他 > 详细

for语句之打印三角形问题

时间:2015-07-09 00:07:04      阅读:270      评论: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 k = 1; k <= a-i; k++)
                {
                    Console.Write("  ");
                }
                for (int x = 1; x <= i*2-1; x++)
                {
                    Console.Write("");
                }
                Console.WriteLine();
            }
            for (int j = 1; j < a; j++)
            {
                for (int k2 = 1; k2 <= j; k2++)
                {
                    Console.Write("  ");
                }
                for (int x2 = 1; x2 <= (a-j)*2-1; x2++)
                {
                    Console.Write("");
                }
                Console.WriteLine();
            }

 

 

for语句之打印三角形问题

原文:http://www.cnblogs.com/franky2015/p/4631609.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!