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

例题:打印正三角形。两层for循环,难点明白行与列的关系

时间:2015-04-14 22:55:59      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:

while (true)
            {
                string s = "★";//s代表五角星
                string t = "○";//t代表方格,如果需要只打印正三角形,可用空格键代替
                int a = 1;//声明变量,初始值为1
                Console.Write("请输入行数");
                a = Convert.ToInt32(Console .ReadLine ());
                for (int i = 1; i <= a; i++)
                {
                    for (int x = 1; x <= a - i; x++)
                    {
                        Console.Write(t);//输出空格,
                    }
                    for (int x = 1; x <= 2 * i - 1; x++)
                    {
                        Console.Write(s);
                    
                    }
                    Console.Write("\n");

打印结果

技术分享

例题:打印正三角形。两层for循环,难点明白行与列的关系

标签:

原文地址:http://www.cnblogs.com/275147378abc/p/4426183.html

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