首页 > Windows开发 > 详细

C#利用for循环打印图形练习题

时间:2019-04-27 20:41:40      阅读:162      评论:0      收藏:0      [点我收藏+]

(1)

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            for(int i = 0; i < 5; i++)//外层循环控制的是行数
            {
                for(int j = 0; j <= i; j++)//内层循环控制的是列数,控制是每行打印的内容及个数
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
            Console.ReadLine();
        }
    }
}

 打印结果如下:

技术分享图片

 (2)

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            
            for(int i = 0; i < 5; i++)
            {
                for(int j = 5; j > i; j--)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
            Console.ReadLine();
        }
    }
}

打印结果如下:

技术分享图片

(3)

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {            
            for(int i = 0; i < 5; i++)//打印行数
            {
                for(int j = 5; j >i+1; j--)//打印空格数列数
                {
                    Console.Write(" ");
                }
                for(int t = 0; t <= i; t++)//打印列数
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
            Console.ReadLine();
        }
    }
}

打印结果如下:

技术分享图片

(4)

namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {
            for(int i = 0; i < 5; i++)
            {
                for(int j = 0; j <=i-1; j++)
                {
                    Console.Write(" ");
                }
                for(int t = 5; t > i; t--)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
            Console.ReadLine();
        }
    }
}

 

打印结果如下:

技术分享图片

 

C#利用for循环打印图形练习题

原文:https://www.cnblogs.com/programme-maker/p/10780057.html

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