码迷,mamicode.com
首页 > Windows程序 > 详细

c# 打印三角菱形

时间:2015-03-03 13:14:29      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

//打印三角菱形
 Console.WriteLine("请输入一个数:");
                int x = Convert.ToInt32(Console.ReadLine());
                string s = "";
                string t = "Δ";
               // string p = "→_→";

                for (int k = 0; k < x; k++)//左下三角
                {
                    for (int l = 0; l <= k; l++)
                    {

                        Console.Write(t);
                    }
                    Console.WriteLine();
                }
                Console.WriteLine("--------------------");
                s = "";
                for (int m = 0; m < x; m++)//左下三角
                {
                    for (int n = m; n >= 0; n--)
                    {
                        Console.Write(t);
                    }
                    Console.WriteLine();
                }

                Console.WriteLine("--------------------");
                s = "";
                for (int mo = 0; mo < x; mo++)//左上三角
                {
                    for (int no = 0; no < x - mo; no++)
                    {
                        Console.Write(t);
                    }
                    Console.WriteLine();
                }

                Console.WriteLine("--------------------");
                s = "";
                for (int ml = 0; ml < x; ml++)//左上三角
                {
                   
                    for (int io = x - ml; io > 0; io--)
                    {

                        Console.Write(t);
                    }
                    Console.WriteLine();
                }
                Console.WriteLine("--------------------");
                s = "";
              
                for (int i = 0; i < x; i++)//尖三角形
                {
                   
                        for (int k = 0; k<x-i; k++)
                    {
                     
                             Console.Write(" ");
                     
                    }
                    s = s + t;
                            Console.Write(s);
                  
                    Console.WriteLine();
                 }
                Console.WriteLine("--------------------");
                s = "";
                for (int i = 0; i < x; i++)//右下三角
                {
                   
                    for (int k = 0; k < x - i; k++)
                    {
                       
                        Console.Write("  ");
                        

                    }
                    s = s + t;
                    Console.Write(s);

                    Console.WriteLine();
                }
                Console.WriteLine("--------------------");
                s = "";
                for (int i = 0; i < x; i++)//右上三角
                {
                   
                    for (int k = 0; k <=i; k++)
                    {
                       
                        Console.Write("  ");
                       

                    }
                    for (int k = 0; k <x- i; k++)
                    {
                  
                    Console.Write(t);
                    }
                    Console.WriteLine();
                }
                Console.WriteLine("--------------------");
                s = "";
                for (int i = 0; i < x-1; i++)//菱形上部
                {
                  
                    for (int k = x; k > i+1; k--)
                    {

                        Console.Write("  ");


                    }
                    for (int k = 2*x; k >2 * (x - i)-1; k--)
                    {

                        Console.Write(t);
                    }
                   
                     Console.WriteLine();
                }
              
                for (int i = 0; i < x; i++)//菱形下部
                {
                    for (int k = 0; k < i; k++)
                    {

                        Console.Write("  ");


                    }
                    for (int k = 0; k <2*( x - i)-1; k++)
                    {
                       
                        Console.Write(t);
                    }
                    Console.WriteLine();
                }

 


                Console.ReadKey();

c# 打印三角菱形

标签:

原文地址:http://www.cnblogs.com/lovesy2413/p/4310478.html

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