首页 > 其他 > 详细

for循环

时间:2015-08-04 00:08:32      阅读:234      评论:0      收藏:0      [点我收藏+]
            Console.Write("请输入数字:");
            int n = int.Parse(Console.ReadLine());
            for (int i = 1; i <= n; i++) 
            {
                for (int t = 1; t <i ;t++ ) 
                {
                    Console.Write("");
                }
                for (int a = n-i+1; a >=1;a--)
                {
                    Console.Write("");
                }
                Console.Write("\n");

            }
            Console.ReadLine();

打印菱形

            Console.Write("请输入数字:");
            int n = int.Parse(Console.ReadLine());
            for (int i = 1; i <= n; i++) 
            {
                for (int t = 1; t <=n-i ;t++ ) 
                {
                    Console.Write("");
                }
                for (int a = 1; a <=2*i-1;a++)
                {
                    Console.Write("");
                }
                Console.Write("\n");

            }
          
            for (int m = 1; m < n; m++)
            {
                for (int p = 1; p<= m; p++)
                {
                    Console.Write("");
                }
                for (int k= 1; k<= 2 * (n-m) - 1; k++)
                {
                    Console.Write("");
                }
                Console.Write("\n");

            }
            Console.ReadLine();

 

for循环

原文:http://www.cnblogs.com/liuyudong0825/p/4700632.html

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